MySql subquery

Discussion in 'Coding Help' started by louie, Jul 6, 2010.

  1. louie

    louie New Member

    I have two tables that are not related in any way because it can not be....

    I want to select all the records from the first table but only if a certain field in the second table = 'yes'

    Any ideas? I am at it for the last half an hour and can't seem to get any results.
     
  2. ziycon

    ziycon New Member

    Try something like the below, works grand for myself on two separate tables. This will return everything from table 1.
    Code:
    SELECT * FROM tbl1, tbl2 WHERE IF(tbl2.col='value','yes','no')='yes';
     
  3. louie

    louie New Member

    Tried that already but not luck.
    I get : "Impossible WHERE noticed after reading const tables" from Mysql DB
     
  4. ziycon

    ziycon New Member

    That message is saying that while the where clause is valid an empty result set was returned, are you sure the IF statement is pointing to a valid table/column?
     
  5. louie

    louie New Member

    Yes it is.
     
  6. ziycon

    ziycon New Member

    Can you throw in 'EXPLAIN' or 'EXPLAIN EXTENDED' in front of the query to get more information from the optimiser?
     

Share This Page