Very simple request in MYSQL but getting no output
I have a very simple query to do and yet I can not, I am fine based on a book. I have two tables: "pages" and "users". In the Pages table, the fields author_id corresponds to id in the users table of the author of the page. "name" is the name of the table field that contains the users name.
Here's where I am:
Code:
SELECT pages.author_id, users.name
FROM pages, users
WHERE pages.id = { $this->id } AND users.id = pages.author_id
No error from mysql but no return when the ID that I provided is correct. It is surely very simple but I do not understand the whole problem
Re: Very simple request in MYSQL but getting no output
Use a JOIN instead of a WHERE condition to join your two tables.
There you met WHERE MyTable.id = my_other_table.fk_id
Use rather FROM MyTable INNER JOIN my_other_table ON id = fk_id
Re: Very simple request in MYSQL but getting no output
author_id is zero so it can not work
Re: Very simple request in MYSQL but getting no output
Quote:
Originally Posted by
XSI
Use a JOIN instead of a WHERE condition to join your two tables.
There you met WHERE MyTable.id = my_other_table.fk_id
Use rather FROM MyTable INNER JOIN my_other_table ON id = fk_id
Why? Does it improves performance, or is it another reason?
Re: Very simple request in MYSQL but getting no output
Yes it improves performance as well as readability.