all groups > sql server programming > april 2004 >
You're in the

sql server programming

group:

SQL select and compare help


Re: SQL select and compare help nib
4/30/2004 9:30:41 PM
sql server programming:

[quoted text, click to view]

Learn it! Love it! Use it! :D Exists is a very handy and useful command. ;)

SQL select and compare help E-Star
4/30/2004 10:03:58 PM
Situation:

Table 1 has car records with a field called 'color'.
Table 2 has a list of all the current 'color's available.

However, the current list in table 2 may not have all the colors
available in table 1........say a certain color is no longer offered,
however there are still cars from the past with that color.

How can I easily get an sql search result to get all the colors from
the records (table 1) which are also in table 2.

Using:
SELECT DISTINCT color FROM table1
I can get all the distinct values from table 1
and using
SELECT color FROM table 2
I can get all the current colors.

Instead of manually comparing each entry, can I easily get sql to do
this comparison for me?

Re: SQL select and compare help E-Star
4/30/2004 10:55:02 PM
I wasn't familiar with EXISTS. This works nicely. THANKS!!


In article <OVm0aFwLEHA.1168@TK2MSFTNGP11.phx.gbl>, Vishal Parkar
[quoted text, click to view]
Re: SQL select and compare help Vishal Parkar
5/1/2004 3:50:52 AM
Try:

select distinct color from table1 a
where exists
(select * from table2 b
where b.color = a.color)


--
Vishal Parkar
vgparkar@yahoo.co.in


AddThis Social Bookmark Button