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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Plz help with optimised sql query..!!

Author  Topic 

dichanz
Starting Member

2 Posts

Posted - 2008-01-23 : 04:33:27
Hi, I am having 1 tables.....
table1 -
id,Lid

table2 -

actid, Lid

table2's Lid is foreign key relation with table1 - Lid
table1 can have id as primary key & Lid can have multiple values...

my query is;;;

select * from table 2 with additional column 'depend' as 1 if lid is present in table1 else 0

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-23 : 04:39:00
[code]SELECT t2.id,
t2.Lid,
CASE
WHEN t1.Lid IS NOT NULL THEN 1
ELSE 0
END AS 'Depend'
FROM table2 t2
LEFT OUTER JOIN table1 t1
ON t1.Lid=t2.Lid[/code]
Go to Top of Page
   

- Advertisement -