howto have condition in a nested SQL query?

Posted by fenec on Stack Overflow See other posts from Stack Overflow or by fenec
Published on 2010-05-12T16:24:05Z Indexed on 2010/05/12 16:34 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

here is my SQL statement , i would like to find all the games that have the status 0 and names of teams that are like key_word or the sport's name that are like the key word. The problem is that all the games that are displayed don't have status 0 . What am i doing wrong?

sql="select * from games where games.status=0 and games.team_2_id
     IN (select id from teams where name like '"+key_word+"')
      or games.team_1_id
        IN (select id from teams where name like '"+key_word+"')
          or games.sport like '"+key_word+"'
            "

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql