Reputation: 1
i have 2 tables
how can i select 2 tables and sorting it by rating?
my query
SELECT
USER_ID,
SUM(RATING)
FROM
USERS,
EXTRA
WHERE
EXTRA.USER_ID = '{$row['USER_ID']}'
Column '
user_id
' in field list is ambiguous
Upvotes: 0
Views: 91
Reputation: 1270411
Never use commas in the FROM
clause. Always use proper explicit JOIN
syntax.
Apart from that, the query is over complicated. You only need to reference once table:
SELECT e.USER_ID, SUM(e.RATING)
FROM EXTRA e
WHERE e.USER_ID = '{$row['USER_ID']}';
Additional notes:
So the query should look more like:
SELECT e.USER_ID, SUM(e.RATING)
FROM EXTRA e
WHERE e.USER_ID = ?
Upvotes: 1
Reputation: 1529
Both of your tables have user_id
column. You must specify which one you want to select:
SELECT users.user_id, SUM(rating) FROM users, extra WHERE extra.user_id ='{$row['user_id']}'
Upvotes: 0