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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query

Author  Topic 

dhinasql
Posting Yak Master

195 Posts

Posted - 2008-07-03 : 09:51:56
Hi Friends,

I have two table named as tbl_property and tbl_favorites

tbl_property contain two column are id,city
tbl_favorites contain 3 columns user_id,prty_id,fav_status

Now i want to display all the rows from tbl_property, from the tbl_favorites i want to display user_id which is equal to 13 and the prty_id = id and the fav_status

Sample Data

tbl_prty
--------
id city
1 LA
2 CA
3 KL
4 CD
5 XL
6 PO
tbl_favorites
--------------
user_id prty_id fav_status
13 2 1
13 3 1
14 3 1

Expected Output is :

id city user_id fav_Status
1 LA 0
2 CA 13 1
3 KL 13 1
4 CD 0
5 XL 0
6 PO 0

Please help me in query, its very urgent...

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-03 : 10:08:57
[code]SELECT p.id, p.city, f.user_id, f.fav_status
FROM tbl_prty p
left JOIN tbl_favorites f ON p.id = f.prty_id[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -