Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL IN() Clause with Sub Select

Status
Not open for further replies.

Korizon67

Programmer
Apr 25, 2007
36
US
I have a Table with the follwing,

+----+------+-----------+
| id | type | vendor |
+----+------+-----------+
| 1 | ppc | google |
| 2 | ppc | quigo |
| 3 | ppc | quigo-aol |
| 4 | ppc | pulse360 |
| 5 | ppc | yahoo |
| 6 | ppc | msn |
+----+------+-----------+

if i run...

SELECT GROUP_CONCAT('\'',`lcr_vendors`.`vendor`,'\'') FROM `lcr_vendors` WHERE `lcr_vendors`.`type` = 'ppc'

I get,

'google','quigo','quigo-aol','pulse360','yahoo','test','msn'

I am running the following...

SELECT `lrc_visits_tmp`.*
FROM `lrc_visits_tmp`
WHERE `lrc_visits_tmp`.`vendor` IN(SELECT GROUP_CONCAT('\'',`lcr_vendors`.`vendor`,'\'') FROM `lcr_vendors` WHERE `lcr_vendors`.`type` = 'ppc');

it returns no results, if I run ...

SELECT `lrc_visits_tmp`.*
FROM `lrc_visits_tmp`
WHERE `lrc_visits_tmp`.`vendor` IN('google','quigo','quigo-aol','pulse360','yahoo','msn');

Anyone have any clue why this query is failing?

SELECT version(); returns 5.0.51b-community

Thanks

Mike

 
I meant to say

it returns no results, if I run ...

SELECT `lrc_visits_tmp`.*
FROM `lrc_visits_tmp`
WHERE `lrc_visits_tmp`.`vendor` IN('google','quigo','quigo-aol','pulse360','yahoo','msn');

I GET results

Sorry Mike
 
instead of this --

GROUP_CONCAT('\'',`lcr_vendors`.`vendor`,'\'')

you should write this --
Code:
GROUP_CONCAT(CONCAT('''',lcr_vendors.vendor,''''))
and then try your IN again

:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top