about searching

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

about searching

Post by bugthefixer »

i have a table which has two colums

Code: Select all

track_id         st_id
1                     34
1                     36
1                     22
1                     2
2                     67
2                     54
3                     55
3                     76
3                     43
3                     98
now i want to select track_id where the search key is two st_ids.

like i want to find track id where st_id=34 and st_id=36

it should give me answer 1.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

So something like:
SELECT * FROM foobar WHERE st_id =34 OR st_id =36 GROUP BY track_id
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

Post by bugthefixer »

well it just gives me distnct data but doesnt give data which contains both the st_id not one of them.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this may be more what you are looking for (untested)

Code: Select all

SELECT a.* FROM foo a, foo b WHERE b.st_id = 36 AND a.st_id = 34
Post Reply