从两个表中选择两列 [英] select two columns from two tables
问题描述
我有两个表.dept和employee,下面显示了结构.这里,did是dept表的主键和employee表的外键.
部门
Dname是否为Dnumber
1 d1 23
2 d2 34
3 d4 67
员工
Eid Ename Did
1 e1 1
2 e2 2
3 e3 2
在这里,我必须选择与Dname有关的Ename ..请有人帮助我..
预先谢谢您.
hi ,i have two tables.dept and employee,Below I have shown the structure .here Did is primary key of dept table and Foreign key of employee table.
dept
Did Dname Dnumber
1 d1 23
2 d2 34
3 d4 67
employee
Eid Ename Did
1 e1 1
2 e2 2
3 e3 2
here ,I have to select Ename with respect to Dname..please someone help me..
thank you in advance
推荐答案
听起来很像作业……您需要做的就是加入.我建议阅读本教程: SQL联接 [
Sounds very much like homework... The thing you need is a join. I suggest going through this tutorial: SQL Joins[^]
如果Did
是dept
表中的PK,并且FK
在employee表中,INNER
子句应类似于:
IfDid
is a PK indept
table andFK
in employee table,INNER
clause should looks like:
FROM dept LEFT JOIN employee ON dept.Did = employee.Did
这意味着:从dept
表中获取所有数据,并从employee
表中获取记录
其余查询尝试编写自己的内容.
It mean: fetch all data from dept
table and metches records from employee
table
The rest of query try to write yourself.
这篇关于从两个表中选择两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!