[thelist] Simple SQL Problem

Fred Jones fredthejonester at gmail.com
Thu Mar 5 14:45:58 CST 2009


I think this will be easy for someone who isn't as tired as I. I have
two tables. To make it simple, one has one field called nid and the
other is a "link" table with two fields: nid and tid. I have data like
this let's say:

nidtable
nid
1
2

linktable
nid  tid
1    5
1    6
2    5

I know how to make a SELECT to get all rows from nidtable that have a
tid of 5 stored in linktable:

SELECT nid from nidtable
LEFT JOIN linktable ON linktable.nid=nidtable.nid
WHERE tid=5;

This will give me 1 and 2.

but how do I make a SELECT to get all rows from nidtable that have
both a 5 and 6 in linktable? I want to get just row 1.

Thanks



More information about the thelist mailing list