-5

Im trying to query my data with the same user_id and error occurs.

SELECT * 
FROM contacts 
JOIN users 
WHERE user_id = 1 
AND user_id = 1;

Error encountered was:

Column 'user_id' in where clause is ambiguous

esqew
  • 42,425
  • 27
  • 92
  • 132

2 Answers2

0

Both the table you're pulling FROM and the table you're JOINing have a field called user_id. Specify which table you want to compare the user_id from:

SELECT * 
FROM contacts 
JOIN users 
WHERE contacts.user_id = 1
AND users.user_id = 1
esqew
  • 42,425
  • 27
  • 92
  • 132
0

Use an explicit JOIN with ON:

SELECT c.*, u.*  -- you should really explicitly list the columns
FROM contacts c JOIN
     users u
     ON c.user_id = u.user_id
WHERE u.user_id = 1 ;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786