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.

6. Return all graphids of those graphs that have some fork nodes but no join nodes.

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

I can't say this question is incomplete because here I know what I have to create 3 tables and tables have attributes and everything is mentioned just one simple problem is that you haven't mentioned anything about the data that needs to be inserted into the table so that based on that I can write the SQL statement but yeah now this is up to me so I will insert data so that it matches with the question and I can formulate SQL statement.

-------------

Graphs Table

create table Graphs(
`graphid` int not null primary key,
`graphname` varchar(20)
);

Nodes Table

create table Nodes(
`nodeid` int not null primary key,
`nodename` varchar(20) not null,
`nodeweight` int not null,
`graphid` int not null,
foreign key(graphid) references Graphs(graphid)
);

Edges Table

create table Edges(
`parentid` int not null,
`childid` int not null,
`edgeweight` int not null,
`graphid` int not null,
primary key(parentid,childid),
foreign key(graphid) references Graphs(graphid)
);

Now the Values that I have added into the tables

Graphs Table

insert into `Graphs`(`graphid`,`graphname`) values
(1,'X'),
(2,'Y'),
(3,'Z');

Nodes Table

insert into `Nodes`(`nodeid`,`nodename`,`nodeweight`,`graphid`) values
(101,'first',10,1),
(102,'fork',20,2),
(103,'join',30,3),
(104,'second',15,1),
(105,'join',5,3);

Edges Table

insert into `Edges`(`parentid`,`childid`,`edgeweight`,`graphid`) values
(102,11,20,1);

Now the query to get all graphics of the graph which have fork nodes but no join nodes

as you cam I have inserted some values in the nodes table with node name as fork,join,first and so on and now we need to fetch value which don't have join nodes and just fork nodes

select graphid from Nodes where nodename ='fork';

This query will return the graphid whose nodename is a fork and nothing else


select graphid from Nodes where nodename not in ('join');

but this query will return all the graphid except the one with nodename join


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