mysql 多表查询等值连接、为表取别名

#案例:查询女神名和对应的男神名

SELECT 
    NAME,boyName
FROM
    boys,beauty
WHERE
    beauty.boyfriend_id=boys.id;

USE myemployees;

#案例:查询employees表的员工名和对应的departments表的部门名,限定字段名相同

SELECT
    last_name,department_name
FROM
    departments,employees
WHERE
    employees.department_id=departments.department_id;

#案例:查询员工名、工种号、工种名,限定字段名和查询字段名相同

SELECT
    last_name,employees.job_id,job_title
FROM
    employees,jobs
WHERE
    employees.job_id=jobs.job_id;

#为表取别名,如果取了别名,则就不能使用原始表名去限定

SELECT 
    last_name,e.job_id,job_title
FROM
    employees AS e,jobs AS j
WHERE
    e.job_id=j.job_id;
    原文作者:wx5d21d5e6e5ab1
    原文地址: https://blog.51cto.com/14437184/2437255
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞