The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MS SQL Development
|
Where value in column list problem
Discuss Where value in column list problem in the MS SQL Development forum on Dev Shed. Where value in column list problem MS SQL Development forum discussing administration, MS SQL queries, and other MS SQL-related topics. SQL Server is Microsoft's enterprise database engine.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 11th, 2012, 03:39 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 13
Time spent in forums: 20 h 41 m 4 sec
Reputation Power: 0
|
|
|
Where value in column list problem
Hi guys,
I'm facing an issue with the following query.
select * from table where form.value in (column.list)
Usually the way queries are set up is the other way around
meaning :
select * from table where column.value in (list)
is there something i can do to make the query work or is there something wrong with my logic?
|

January 11th, 2012, 05:07 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
|
your logic is fine
... WHERE somevalue IN ( list, of, columns )
this is valid and will work
|

January 11th, 2012, 05:53 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 13
Time spent in forums: 20 h 41 m 4 sec
Reputation Power: 0
|
|
|
@r937
thanks for the reply. one thing perhaps wasn't clear is that column.list is not a list of columns.
it's a list stored in one field in the DB.
so it's where 2 in (12,3,4,5,2)
2 is coming from a form.
12,3,4,5,2 is stored in the field.
|

January 11th, 2012, 06:11 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by Abnaxus78 ...column.list is not a list of columns.
it's a list stored in one field in the DB. | very poor design
you neglected to mention which database system you're using
if it's mysql, you may use the FIND_IN_SET function, but be aware that it requires a table scan and your query will get slower and slower the more rows you have
if it's some other database system, things progress downhill, you may have to use a patchwork involving SUBSTRING, and, like mysql, it won't scale
|

January 11th, 2012, 06:18 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 13
Time spent in forums: 20 h 41 m 4 sec
Reputation Power: 0
|
|
|
i'm using MSSQL.
I'll see what i can do to change the db design.
thanks
|

January 11th, 2012, 12:10 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by Abnaxus78 I'll see what i can do to change the db design. | that's the best strategy all around
meanwhile, i;ve moved the thread to the MSSQL forum
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|