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
 select multiple entries based on same value?

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-09 : 09:13:29
i'm attempting to do the following:
USE ARREST
SELECT * FROM arrest WHERE ecsoid = 'GCSO00MNI000524', 'GCSO00MNI006163','GCSO00MNI032352'

I actually have about 153 ECSOID numbers from a table that i need to select into a single new table. Obviously the above won't work. how do i accomplish this?

thanks

singularity
Posting Yak Master

153 Posts

Posted - 2012-02-09 : 09:15:39
[code]
SELECT * FROM arrest WHERE ecsoid in ('GCSO00MNI000524', 'GCSO00MNI006163','GCSO00MNI032352')
[/code]
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-09 : 09:23:39
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 14:01:40
quote:
Originally posted by WJHamel

i'm attempting to do the following:
USE ARREST
SELECT * FROM arrest WHERE ecsoid = 'GCSO00MNI000524', 'GCSO00MNI006163','GCSO00MNI032352'

I actually have about 153 ECSOID numbers from a table that i need to select into a single new table. Obviously the above won't work. how do i accomplish this?

thanks


if numbers are coming from a table then why list the values in select again inside IN. why not simply join to table or use EXISTS?


USE ARREST
SELECT a.* FROM arrest a
INNER JOIN ECSOIDNumbertable t
ON t.ecsoid = a.ecsoid


or

USE ARREST
SELECT a.* FROM arrest a
WHERE EXISTS(SELECT 1 FROM ECSOIDNumbertable t
WHERE t.ecsoid = a.ecsoid )




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -