_ Query the database connection

Join queries
1, cross-connect
select * from EMP; single table query
select * from emp, dept; query two tables
select * from emp cross join dept;
Cartesian product
2, the connector
in the display, connecting standard
select * from emp as a inner join dept as b
on a.dept_id = b.id; implicit within the connector, where conditional on the basis of the result set filtering
select * from emp as a, dept as b where a.dept_id = b.id ;
inner connecting the Join
SELECT * from the Join Dept EMP AS AS A B = ON a.dept_id b.id;
inner connecting the Join cross
SELECT * from EMP AS AS A cross the Join Dept B = ON a.dept_id b.id;
the MySQL in cross and inner join on the Join results on the same
standard sql, cross join can not be used on, MySQL support on
special within the connector, the connector is not equivalent
select * from emp as a inner join dept as b on a.dept_id> b.id;
special within connection connection
* from EMP AS A SELECT the Join Inner EMP AS B = ON a.id b.leader;
. 3, the outer connecting
content external display connected> = inner connecting
left outer, left table based table
select * from emp as a left outer join dept as b on a.dept_id = b.id
; right outer join, right table-based table
select * from emp as a right outer join dept as b on a.dept_id = b.id;
outer joins, the query from the table empty data
select * from emp AS AS a Dept B left on the Join a.dept_id = b.id
 where b.id iS null;
the difference between the on and where
on how to link two tables, where the results of the screening set do
select * from emp A left the Join Dept AS AS B ON (= a.dept_id b.id and b.id IS null);
ON priority WHERE
SELECT * from EMP AS AS A left the Join Dept B = ON a.dept_id b.id WHERE b.id null IS;
. 4, fully connected full, unionq deduplication, union all not re-
select * from emp as a left join dept as b on a.dept_id = b.id
union
select * from emp as a right join dept as b on a.dept_id = b.id;

Guess you like

Origin www.cnblogs.com/JacquelineQA/p/12563236.html