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
 Help with SELECT

Author  Topic 

Access
Starting Member

44 Posts

Posted - 2007-11-03 : 17:06:26
I have two temp tables that I'm creating on the fly.It is basically the words and their synonyms.
1.
ID NAME
1 FAST
2 WHILD
1 QUICK
3 SUNNY
4 PERFECT
3 BRIGHT

2.
ID
3
2

I need to have a query which will return everything from first (1) table with identified rows that are in the second (2) table. The identifier can be anything, lets put word "-selected" next to matched name for now.

In this case it will be next output:

FAST
WHILD - selected
QUICK
SUNNY - selected
PERFECT
BRIGHT - selected


Thank you

nr
SQLTeam MVY

12543 Posts

Posted - 2007-11-03 : 18:02:01
select t1.name, case when t2.ID is null then '' else 'selected' end
from #t1 t1
left join #t2 t2
on t1.ID = t2.ID

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Access
Starting Member

44 Posts

Posted - 2007-11-04 : 00:59:08
quote:
Originally posted by nr

select t1.name, case when t2.ID is null then '' else 'selected' end
from #t1 t1
left join #t2 t2
on t1.ID = t2.ID

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.



M-V-P....M-V-P

Thanks it works.

Go to Top of Page
   

- Advertisement -