Querying Two Tables At Once

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-19T06:02:54Z Indexed on 2010/03/19 6:11 UTC
Read the original article Hit count: 285

Filed under:

Hello,

I am trying to do what I believe is called a join query. First, in a MySQL table called "login," I want to look up what "loginid" is in the record where "username" equals $profile. (This will be just one record / row in the MySQL table).

Then, I want to take that "loginid" and look up all rows / records in a different MySQL table called "submission," and pull data that have that "loginid." This could possibly be more than one record / row. How do I do this?

The code below doesn't seem to work.

Thanks in advance,

John

  $profile = mysql_real_escape_string($_GET['profile']);

  $sqlStr = "SELECT l.username, l.loginid, s.loginid, s.submissionid, s.title, s.url, s.datesubmitted, s.displayurl
               FROM submission AS s,
           login AS l
              WHERE l.username = '$profile',
           s.loginid = l.loginid
           ORDER BY s.datesubmitted DESC";

© Stack Overflow or respective owner

Related posts about sql