#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    france
    Posts
    35
    Rep Power
    15
    Hi there.

    I'd like to know why
    SELECT ... FROM ... WHERE variable IN (SELECT ... FROM ... WHERE ...)
    doesn't work, although it works if I write the result of the second query as IN arguments, like
    SELECT ... FROM ... WHERE variable IN ('variable1', variable2', 'variable3', ...)

    Thanks

    -
    J0f
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    That's known as a sub-select. MySQL does not currently support sub-selects.

    If your queries are sufficiently simple, you can work around it:

    select t.* from table1 t, table2 t2 where t.variable=t2.somefield and t2.someotherfield='foo';
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    france
    Posts
    35
    Rep Power
    15
    with php/mysql, do I have to :
    - do my subquery first
    - output the result as a text variable
    - do the initial query with subselection of the previous results ?

    Thanx

    -
    J0f
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You can either do a select to build the IN clause or join the tables. If you want a detailed example, post your non-working query in it's entirety.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    2
    Rep Power
    0
    I think that this question falls in the same line as this thread so I am going to ask it.

    Is this considered the same as a sub-query that is not supported?

    SELECT Table1.fields, Table2.fields
    FROM Table1
    Left Join (SELECT fields
    FROM junk) as Table2
    on Table1.key = Table2.FKey

    Thanks for the help.
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Yes.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    2
    Rep Power
    0
    That is a serious limitation... Hope they fix it soon.

Similar Threads

  1. Requesting help on READTEXT statement
    By hdokes in forum MS SQL Development
    Replies: 1
    Last Post: March 19th, 2004, 08:53 AM
  2. Question about the WHERE statement
    By layz d in forum MS SQL Development
    Replies: 5
    Last Post: January 28th, 2004, 11:58 AM
  3. how can i put an IF statement inside a WHILE statement?
    By Jarrett Green in forum Perl Programming
    Replies: 4
    Last Post: December 22nd, 2003, 10:05 PM
  4. Replies: 7
    Last Post: October 10th, 2003, 08:13 AM
  5. selct statement help
    By p_murugappan in forum PHP Development
    Replies: 7
    Last Post: September 25th, 2003, 10:51 AM

IMN logo majestic logo threadwatch logo seochat tools logo