本篇文章為大家帶來了關於mysql的相關知識,其中主要介紹了關於多表查詢的相關內容以及一些案例分享,包括了查詢員工的姓名、年齡、職位等等內容,下面一起來看一下,希望對大家有幫助。
推薦學習:mysql影片教學
create table salgrade( grade int, losal int, hisal int ) comment '薪资等级表'; insert into salgrade values (1,0,3000); insert into salgrade values (2,3001,5000); insert into salgrade values (3,5001,8000); insert into salgrade values (4,8001,10000); insert into salgrade values (5,10001,15000); insert into salgrade values (6,15001,20000); insert into salgrade values (7,20001,25000); insert into salgrade values (8,25001,30000);
select e.name , e.age , e.job , d.name from emp e , dept d where e.dept_id = d.id;
select e.name , e.age , e.job , d.name from emp e inner join dept d on e.dept_id =d.id where e.age < 30;
select distinct d.id , d.name from emp e , dept d where e.dept_id = d.id;
select e.*, d.name from emp e left join dept d on e.dept_id = d.id where e.age >40 ;
連接條件: emp.salary >= salgrade.losal and emp.salary <= salgrade.hisal
-- 方式一 select e.* , s.grade , s.losal, s.hisal from emp e , salgrade s where e.salary >= s.losal and e.salary <= s.hisal; -- 方式二 select e.* , s.grade , s.losal, s.hisal from emp e , salgrade s where e.salary between s.losal and s.hisal;
推薦學習:
mysql影片教學以上是MySQL基礎之多表查詢案例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!