0

I have found a lot of answers regarding joining two SELECT statements using UNION. However, I am trying to do something like this:

$sql = "SELECT 'column' 
        FROM 'table' 
        WHERE 'id' = (
                        SELECT 'column' 
                        FROM 'another_table' 
                        WHERE 'id' = 'something_specific'
                    )"

Can this not be done or am I doing something wrong?

Thanks

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Mike
  • 254
  • 1
  • 6
  • 16
  • Is this generating an error by any chance, or was this just a carelessly written example – RiggsFolly Aug 23 '17 at 08:49
  • Ignoring the errors in your SQL, are you looking for `JOIN`? – Jonnix Aug 23 '17 at 08:50
  • Thanks, I'm deleting this question. It was not mixing the statements that I was doing wrong. I was not correctly using a php variable in the statement. The statement is fine as I have generically written it. – Mike Aug 23 '17 at 08:52
  • That query contain errors. Read the duplicate-link – M. Eriksson Aug 23 '17 at 08:53
  • The single quote marks were just to determine names, I'm not actually using them in the query. Sorry, I'm new to SQL and didn't fully understand the importance of the single quotes. – Mike Aug 23 '17 at 08:54
  • Also use MySQLi or PDO instead of MySQL because it is deprecated and you can easily get a SQL injection attack! – Mr Pro Pop Aug 23 '17 at 09:14

0 Answers0