Reputation: 858
I have a query which looks like this
$db->query("SELECT A.page_id, A.page_name FROM user_likes_pages as A , user_likes as B WHERE A.page_id = B.page_id AND B.country_id = ".$user_reg." ");
The thing is, I want to select a column from user_likes
. Do I have to make a join or I can do it in different way. Thank you.
Upvotes: 0
Views: 35
Reputation: 1269483
You have a join
in your query, but it is implicit. You should write the query as:
SELECT ulp.page_id, ulp.page_name, ul.<whatever>
FROM user_likes ul JOIN
user_likes_pages ulp
ON ul.page_id = ulp.page_id
WHERE ul.country_id = ".$user_reg."
In addition to adding the explicit join
syntax, I also changed the table aliases so they are abbreviations of the table name. This makes it easier to read the query and avoid mistakes.
Upvotes: 1
Reputation: 2865
You select B.columnname. You don't need a join, because you have the A.page_id = B.page_id.
Upvotes: 1