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 |
|
hazem_world
Starting Member
3 Posts |
Posted - 2010-09-14 : 10:28:00
|
plz help me to choose '999' only from the two select statements as the "station_id" is 3 and 5 select trains.name , journey.station_id , journey.timefrom trains left join journey on trains.id=journey.trainIdwhere station_id=3select trains.name , journey.station_id , journey.timefrom trains left join journey on trains.id=journey.trainIdwhere station_id=57azooom |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-14 : 10:44:02
|
select trains.name , journey.station_id , journey.timefrom trains left join journey on trains.id=journey.trainIdwhere journey.station_id in (3,5)and trains.name = '999' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
hazem_world
Starting Member
3 Posts |
Posted - 2010-09-14 : 10:55:59
|
| thx webfreed i don't want trains.name='999' i've just type it to illustratei want sql to get all trains that have station_id = 3 and 5 but where journey.station_id in (3,5) get station_id = 3 or 57azooom |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-14 : 11:06:05
|
select t1.name , j1.station_id , j1.timefrom trains t1 left join journey j1 on t1.id=j1.trainIdwhere j1.station_id = 3and exists(select * from trains t2 left join journey j2 on t2.id=j2.trainId where j2.station_id = 5 and t2.name = t1.name) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
hazem_world
Starting Member
3 Posts |
Posted - 2010-09-14 : 11:17:02
|
| oops thaaaaaaaaaaank you very very very much :)7azooom |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-14 : 11:20:25
|
You're welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|