Jump to content



Photo

MySql check if (list of items or query) is subset of another query

mysql

  • Please log in to reply
3 replies to this topic

#1 +_Alexander

_Alexander

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 21-January 13
  • Location: USA
  • OS: W8.1 u1
  • Phone: Nokia 521

Posted 17 August 2013 - 05:50

Something like this,

WHERE (/* LIST OF STUFF PASSED IN */) ARE IN (/* QUERY */)

Well actually one will be a list of things I pass in.

 

EDIT: Apparently you cannot union of list of params eg UNION ('a', 'b', 'c')

EDIT 2: Apparently a comma separated list of stuff is not the same as a query of one column :|


Edited by _Alexander, 17 August 2013 - 06:18.



#2 ILikeTobacco

ILikeTobacco

    Neowinian Senior

  • Joined: 08-July 10

Posted 17 August 2013 - 06:05

Something like this,

WHERE (/* QUERY 1 */) ARE IN (/* QUERY 2 */)

Well actually one will be a list of things I pass in.

 

EDIT: Apparently you cannot union of list of params eg UNION ('a', 'b', 'c')

If you save each query as a view and then do a union, you should be able to do what you are trying.



#3 OP +_Alexander

_Alexander

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 21-January 13
  • Location: USA
  • OS: W8.1 u1
  • Phone: Nokia 521

Posted 17 August 2013 - 06:17

Actually the outer query is to get an article id

WHERE (list of tags passed in as parameters) are in (query to get all tags on that specific article)

 

I think I can do it with count but it is visually messy.



#4 Kami-

Kami-

    ♫ d(-_-)b ♫

  • Tech Issues Solved: 3
  • Joined: 28-July 08
  • Location: SandBox

Posted 19 August 2013 - 11:45

Hi,

 

This is a really simple one, you use the IN clause...

SELECT *
FROM tblMain
WHERE mainId IN
(
    SELECT subId
    FROM tblSub
)

More info: http://www.tutorials...l-in-clause.htm