Learn how to use inner joins and where clauses in MySQL
P粉496886646
P粉496886646 2024-01-16 23:04:24
0
1
396

I have two independent tables, namely tuition and user. In the tuition table, I have two fields named user_id and admin_id. I use Inner Join clause with user_id to access related users:

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id

But in the tuition table, I only want to join those records where admin_id is equal to 1. How should I rewrite the above clause? I wrote the following code, but it doesn't show any results:

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE admin_id=1
SELECT * FROM tuition t WHERE admin_id=1 AND JOIN user u ON t.user_id = u.id

P粉496886646
P粉496886646

reply all(1)
P粉564192131

The where clause of the inner join query should reference the table name.

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE table_name.admin_id=1
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template