Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
eldan
Starting Member
2 Posts |
Posted - 2008-11-04 : 16:34:00
|
I have this 2 tables (actually I have more but it's the same problem so it doesn't matter):tblAnimesID --> KEY int extra auto_incrementname --> Textpic --> Textgenere --> Textinfo --> TexttblEpisodesID --> KEY int extra auto_incrementidAnime --> intname --> Textdownload --> Textof course there's a connection between them of 1 to many so the values in the field ID are unique and it can't hold a value more than once and the field idAnime can hold the same value as many times as necessary.now what I want to do is a query that will give me the fields ID and name from tblAnimes buttttttt only where the value in ID exists on the other table in idAnime.for an example if I have on tblAnimesID - 1name - aaaa...ID - 2name - bbb...and on tblEpisodeID - 1idAnime - 1...ID - 2idAnime - 1...now I only have the value 1 on idAnime and I don't have the value 2so the query will only show meID - 1 name - aaaand will only show me that once although there's 2 records where idAnime = 1 the point is that it will show me the fields on tblAnime only if a value from tblAnime exists on tblEpisodes so please if you know the way hellllppp |
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2008-11-04 : 16:49:11
|
Use a subquery.SELECT A.ID, A.nameFROM tblAnime AWHERE A.ID IN (SELECT idAnime FROM tblEpisode)---------------------------EmeraldCityDomains.com |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2008-11-04 : 17:11:45
|
Tara, I prefer joins most of the time, too, but doesn't that get you multiple listings of the same A record if there are multiple E records? You could throw in a DISTINCT, but I like those even less than subqueries. ---------------------------EmeraldCityDomains.com |
 |
|
eldan
Starting Member
2 Posts |
Posted - 2008-11-05 : 13:54:45
|
Thank you both very much it works perfectly now.I actually like subqueries :D but one way or another I decided to use IN because it's more simple for me anyway, (and I don't remember What JOIN does.. ;p lol) |
 |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-11-05 : 18:56:01
|
quote: Originally posted by eldan Thank you both very much it works perfectly now.I actually like subqueries :D but one way or another I decided to use IN because it's more simple for me anyway, (and I don't remember What JOIN does.. ;p lol)
Then you should be reading about joins. |
 |
|
|
|
|