先创建两张表
CREATE TABLE employees (
employee_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
position VARCHAR(50),
salary DECIMAL(10, 2)
);
INSERT INTO employees (employee_id, name, position, salary)
VALUES
(1, 'John Doe', 'Manager', 5000.00),
(2, 'Jane Smith', 'Engineer', 4500.00),
(3, 'Bob Johnson', 'Analyst', 4000.00),
(4, 'Alice Brown', 'Marketing Specialist', 3500.00),
(5, 'Mike Davis', 'Sales Representative', 3000.00),
(6, 'Sarah Harris', 'HR Representative', 2500.00),
(7, 'Alex Thompson', 'Technician', 2200.00),
(8, 'Emily Davis', 'Intern', 2000.00),
(9, 'David Lee', 'Contractor', 2500.00),
(10, 'Olivia Martinez', ' Temp', 2250.00);
CREATE TABLE `departments` (
`department_id` int(11) NOT NULL AUTO_INCREMENT,
`department_name` varchar(30) DEFAULT NULL,
`location_id` int(11) NOT NULL,
PRIMARY KEY (`department_id`),
UNIQUE KEY `department_name` (`department_name`)
) ENGINE=InnoDB AUTO_INCREMENT=1006 DEFAULT CHARSET=utf8;
INSERT INTO `departments` VALUES ('1005', '开发部', '105');
执行如下的sql语句
-- 其实就是两个表要进行关联查询使用的那个连接字段
select * from employees join departments using(department_id)
-- 等同于
select * from employees e join departments d on e.department_id = d.department_id
标签:name,employees,departments,关键字,MySQL,department,using,id
From: https://www.cnblogs.com/dongyaotou/p/18311049