SQL grrr

2011-09-26 Thread Richard White
Hi, i know this is probably a simple answer and i probably drunk too much coffee! given the following sql data: ID value 1 A 1 B 1 C 2 A 2 B 3 A 3 B 3 C i need to run a query that says return me the ids that are linked to values A and B and C. so this query on the

Re: SQL grrr

2011-09-26 Thread Matt Quackenbush
Something like... SELECT ID FROM MyTable WHERE value IN (cfqueryparam cfsqltype=cf_sql_varchar value=#myList# list=true /) ; ?? On Mon, Sep 26, 2011 at 12:18 PM, Richard White rich...@j7is.co.uk wrote: Hi, i know this is probably a simple answer

Re: SQL grrr

2011-09-26 Thread Leigh
ids that are linked to values A and B and C. If you mean only ID's linked to all three (3) values?  Something like this cfset distinctValues = A,B,C ... SELECT  ID, COUNT(Value) AS MatchCount FROM TableName WHERE   ID IN ( cfqueryparam value=#distinctValues# list=true

Re: SQL grrr

2011-09-26 Thread Carl Von Stetten
Richard, I think this will work (untested, assumes SQL Server): select t.ID from mytable t inner join mytable a on t.id = a.id and a.value = 'A' inner join mytable b on t.id = b.id and b.value = 'B' inner join mytable c on t.id = c.id and c.value = 'C' HTH, Carl

Re: SQL grrr

2011-09-26 Thread Steve Milburn
I'm sure there is a much more efficient way of doing this, but this would work: SELECT distinct ID from table where id in (select ID from table where val = 'A' and id in (select id from table where val = 'B' and ID in (select id from table where val = 'C'))) On Mon, Sep 26, 2011 at 1:18 PM,

Re: SQL grrr

2011-09-26 Thread Josh Nathanson
Yup, I think Carl's is the best, though you'd probably want to throw a GROUP BY in there so you don't get multiple rows for the same ID. -- Josh On Mon, Sep 26, 2011 at 10:41 AM, Carl Von Stetten vonner.li...@vonner.netwrote: Richard, I think this will work (untested, assumes SQL Server):

Re: SQL grrr

2011-09-26 Thread Carl Von Stetten
Or change the first line to: select distinct t.ID (again assumes SQL Server) Carl On 9/26/2011 10:44 AM, Josh Nathanson wrote: Yup, I think Carl's is the best, though you'd probably want to throw a GROUP BY in there so you don't get multiple rows for the same ID. -- Josh On Mon, Sep 26,

Re: SQL grrr

2011-09-26 Thread Richard White
thanks, works perfect! Hi, i know this is probably a simple answer and i probably drunk too much coffee! given the following sql data: ID value 1 A 1 B 1 C 2 A 2 B 3 A 3 B 3 C i need to run a query that says return me the ids that are linked to

Re: SQL grrr

2011-09-26 Thread Leigh
If you mean only ID's linked to all three (3) values?  Something like this Duh. Just noticed I left off the GROUP BY...   cfset distinctValues = A,B,C ... SELECT  ID, COUNT(Value) AS MatchCount FROM TableName WHERE   ID IN ( cfqueryparam value=#distinctValues# list=true