Search code examples
mysqlsqlinner-join

SQL inner join issue with getting exact value by id


I have such query:

SELECT `type` FROM `data_user` table1 INNER JOIN
`user_type` table2 ON table1.username = 'sber'

I'm getting all rows from user_type, but I need only the type value in table user_type where id equals to the id from data_user.

How to fix this query for what I want?


Solution

  • SELECT `type` 
    FROM `data_user` table1 
    INNER JOIN `user_type` table2 ON (table1.username = 'sber' AND 
        table1.id = table2.id)