create table data {
id int,
n1 int not null,
n2 int not null,
n3 int not null,
n4 int not null,
primary key (id)
}
and what I need to do is return the relation with tuples (n1, n2, n3) where all the corresponding values for n4 are 0. The problem asks me to solve it WITHOUT using subqueries(nested selects/views)
e.g. for:
insert into data (id, n1, n2, n3, n4) values (111, 2,4,7,0), (222, 2,4,7,0), (333, 3,6,9,8), (444, 1,1,2,1), (555, 1,1,2,0), (666, 1,1,2,0), (777, 5,3,8,0), (888, 5,3,8,0), (999, 5,3,8,0);
the query should return:
(2,4,7)
(5,3,8)
I've been studying sql for a week now but I'm stuck on this. The best I could come up with was:
SELECT DISTINCT n1, n2, n3
FROM data a, data b
WHERE a.ID <> b.ID
AND a.n1 = b.n1
AND a.n2 = b.n2
AND a.n3 = b.n3
AND a.n4 = b.n4
AND a.n4 = 0
but I have nothing to test the query and I get the feeling it's completely wrong.
Any help would really be appreciated!
This post has been edited by macosxnerd101: 12 March 2011 - 03:42 PM
Reason for edit:: Please use code tags

New Topic/Question
Reply



MultiQuote










|