Question

Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid,...

Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid, childid, edgeweight, graphid), formulate a SQL statement for each query in the following.

7. Return all graphids of those graphs such that the graph has at least 1 node that is not connected to any other nodes (i.e. neither as a parent nor as a child).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SQL command:

SELECT graphid FROM Nodes WHERE nodeid NOT IN (SELECT DISTINCT Nodes.nodeid FROM Nodes JOIN Edges ON Nodes.nodeid = Edges.parentid OR Nodes.nodeid = Edges.childid);

Let me explain the query.

  • SELECT DISTINCT Nodes.nodeid FROM Nodes JOIN Edges ON Nodes.nodeid = Edges.parentid OR Nodes.nodeid = Edges.childid
    • It joins tables Nodes and Edges on nodeid from the nodes table and parentid / childid from the edges table. From this joined table, it select distinct nodeid. These nodeid represents nodes which have an edge.
  • SELECT graphid FROM Nodes WHERE nodeid NOT IN ( SUBQUERY )
    • ​​​​​​​It then select all graphids from the table Nodes which have a node other than those returned by the above subquery.
Add a comment
Know the answer?
Add Answer to:
Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT