mysql - combining 2 tables with different condition <p>Here i have 2 tables user and userStore</p> <pre><code>user Table ╔════╦══════╦════════╦═══════════╗ ║ ID ║ NAME ║ ROLE ║ STORECODE ║ ╠════╬══════╬════════╬═══════════╣ ║ 1 ║ A ║ Admin ║ ║ ║ 2 ║ B ║ Store ║ 1 ║ ║ 3 ║ C ║ Store ║ ║ ║ 4 ║ D ║ Client ║ ║ ║ 5 ║ E ║ Staff ║ ║ ╚════╩══════╩════════╩═══════════╝ userStore Table ╔════╦══════════╗ ║ ID ║ CATEGORY ║ ╠════╬══════════╣ ║ 1 ║ X ║ ║ 2 ║ X ║ ╚════╩══════════╝ Output ╔════╦══════╦════════╦═══════════╦══════════╗ ║ ID ║ NAME ║ ROLE ║ STORECODE ║ CATEGORY ║ ╠════╬══════╬════════╬═══════════╬══════════╣ ║ 1 ║ A ║ Admin ║ ║ ║ ║ 2 ║ B ║ Store ║ 1 ║ X ║ ║ 4 ║ D ║ Client ║ ║ ║ ║ 5 ║ E ║ Staff ║ ║ ║ ╚════╩══════╩════════╩═══════════╩══════════╝ </code></pre> <p>I want to fetch all the rows from user table with the role other than store. And wanted to include the store role only if it have match in the userstore table. In the output you can see that the id=3 is not available since it doesn't have match from user store.</p>