为简单起见,假设所有相关字段都是NOT NULL.
你可以做:
SELECT
table1.this, table2.that, table2.somethingelse
FROM
table1, table2
WHERE
table1.foreignkey = table2.primarykey
AND (some other conditions)
Run Code Online (Sandbox Code Playgroud)
要不然:
SELECT
table1.this, table2.that, table2.somethingelse
FROM
table1 INNER JOIN table2
ON table1.foreignkey = table2.primarykey
WHERE
(some other conditions)
Run Code Online (Sandbox Code Playgroud)
这两个是以同样的方式工作MySQL吗?
我有三个名为的表
**Student Table**
-------------
id name
-------------
1 ali
2 ahmed
3 john
4 king
**Course Table**
-------------
id name
-------------
1 physic
2 maths
3 computer
4 chemistry
**Bridge**
-------------
sid cid
-------------
1 1
1 2
1 3
1 4
2 1
2 2
3 3
3 4
4 1
4 2
Run Code Online (Sandbox Code Playgroud)
现在用他研究过的课程名称来显示学生姓名,
**Result**
---------------------------
Student Course
---------------------------
ahmed physic
ahmed maths
ahmed computer
ahmed chemistry
ali physic
ali maths
john computer
john chemistry
king physic
king maths …Run Code Online (Sandbox Code Playgroud) 我想知道SQL在这些连接语句上执行的方式是否有任何不同:
SELECT * FROM a,b WHERE a.ID = b.ID
SELECT * FROM a JOIN b ON a.ID = b.ID
SELECT * FROM a JOIN b USING(ID)
Run Code Online (Sandbox Code Playgroud)
有性能差异吗?还是算法差异?
或者只是语法糖?