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 |
|
j-in-nz
Starting Member
17 Posts |
Posted - 2007-03-25 : 20:47:51
|
| 3 tablesProvince1.Prov12.Prov2DistrictProvId DistrictId Name2 1 District12 2 District22 3 District3 PagesDistID Page Title2 district2IntroPage Intro3 district3AboutPage About3 district3IntroPage IntroI want to return all rows from District table where title = 'Intro' from Pages table.resultDistrict1 nullDistrict2 nullDistrict3 district3IntroPage do I need a select within a select. Once I add the where criteria, I do not get all district values.any help? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-25 : 20:50:51
|
[code]select d.Name, p.Pagefrom District d left join Pages pon d.DistrictId = p.DistID[/code] KH |
 |
|
|
j-in-nz
Starting Member
17 Posts |
Posted - 2007-03-25 : 21:01:33
|
| Hi KH,Thank u for your reply, that works but once I add the where clause, i don't get all from District table |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-25 : 21:04:25
|
can you post your query ? KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-25 : 21:46:27
|
[code]select d.Name, p.Pagefrom District d left join Pages pon d.DistrictId = p.DistIDand p.title = 'Intro'[/code] KH |
 |
|
|
j-in-nz
Starting Member
17 Posts |
Posted - 2007-03-25 : 21:49:46
|
| select d.Name, p.Pagefrom District d left join Pages pon d.DistrictId = p.DistIDwhere p.Title = 'Intro'I get a result of :District3 district3IntroPage which is not what I want. So do I need something like this:select d.Name,(Select Page from Pages where page.districtID = district.DistrictID and Title='Intro') as Pagefrom District d left join Pages pon d.DistrictId = p.DistIDthis returned the fol. error:Subquery returned more than 1 value. |
 |
|
|
j-in-nz
Starting Member
17 Posts |
Posted - 2007-03-25 : 21:53:43
|
Thanks a million KH your query did the trick |
 |
|
|
|
|
|
|
|