SELECT images.user_id, users.user_id
FROM images
AS user_id
LEFT JOIN users
AS user_id
ON users.user_id=images.user_id
WHERE images.user_id = users.user_id
should be
Code:
SELECT img.user_id, usr.user_id
FROM images AS img
LEFT JOIN users AS usr
ON usr.user_id=img.user_id
WHERE img.user_id = usr.user_id
in the process of joining the tables, you were actually renaming both tables to the same name, which cannot be done. so I changed the name of the tables to a different short hand, then i carried that through the rest of the query... however you could have left out the shorthand, and you would have received this query
Code:
SELECT images.user_id, users.user_id
FROM images
LEFT JOIN users
ON users.user_id=images.user_id
WHERE images.user_id = users.user_id
that would still error out though, because both fields are named the same thing, so one of them you would need to create a shorthand.
Code:
SELECT images.user_id, users.user_id AS usr_user_id
FROM images
LEFT JOIN users
ON users.user_id=images.user_id
WHERE images.user_id = users.user_id
and the last bit of this, is that you do not need to JOIN
the tables twice... I am not sure if this causes an error or not, but it definitely isnt necessary. The JOIN
clause is meant to be the way to associate and "bring in" additional tables, and the WHERE
clause is supposed to limit the results... so something like
Code:
... FROM tbl1 JOIN tbl2 ON tbl1.__=tbl2.__
would grab every result where the fields from table1 and table2 matched
where as
Code:
... FROM tbl1 JOIN tbl2 ON tbl1.__=tbl2.__ WHERE tbl1.id>100
would grab every result where the fields from table1 and table2 matched AND where the id on table1 was less than 100
so in the second statement, I am putting that 1 extra limitation. so to return to your query, If you would like every image in the database, then you can just delete the WHERE
clause, however if you wanted to limit it to a specific user... like say grab every image this user has uploaded to display on their portfolio page or whatever, you would include the WHERE
and populate it with the user id of that person
all images
[CODE]
Code:
SELECT images.user_id, users.user_id AS usr_user_id
FROM images
LEFT JOIN users
ON users.user_id=images.user_id
images from 1 person
Code:
SELECT images.user_id, users.user_id AS usr_user_id
FROM images
LEFT JOIN users
ON users.user_id=images.user_id
WHERE users.user_id=__
Bookmarks