Search code examples
mysqlinner-join

MySQL Query: retrieve information from two tables without having to do two queries


I have two tables in my database, and I would like to retrieve information from both of them without having to do two queries. Basically, the user_ID(s) retrieved from the tasks table needs to be used to get those respective user(s) names from the users table. This is what I have so far, but the query is returning false:

SELECT t.user_id, t.nursery_ss, t.nursery_ws, t.greeter, t.date
   u.user_first_name, u.user_last_name
   FROM tasks_tbl AS t
   INNER JOIN users_tbl AS u ON t.user_id = u.user_id
   WHERE t.date = '2009-11-29'

Solution

  • You forgot a comma after t.date in your select-list:

    SELECT t.user_id, t.nursery_ss, t.nursery_ws, t.greeter, t.date -- comma needed here
       u.user_first_name, u.user_last_name
    FROM tasks_tbl AS t
    INNER JOIN users_tbl AS u ON t.user_id = u.user_id
    WHERE t.date = '2009-11-29'