从两个表中选择两列 [英] select two columns from two tables

查看:86
本文介绍了从两个表中选择两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表.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[^]


如果Diddept表中的PK,并且FK在employee表中,INNER子句应类似于:
If Did is a PK in dept table and FK 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆