MySQL在结果集中连接两个表,并根据第一个表添加新列

时间:2013-08-31 06:40:31

标签: php mysql

Employee

employee

Designation

designation

我想在指定表中显示结果集中的名称。我正在使用nic搜索数据。

帮帮我

谢谢

4 个答案:

答案 0 :(得分:1)

select e.serial_no, d.designation, e.name, e.epf_no, e.appointment_date, e.nic, e.dob 
from employee e, designation d 
where e.designation = d.number and e.nic = 'the_number_you_want'

答案 1 :(得分:0)

例如,如果我们必须为893041699 nic number

取指定值
select d.designation from designation d
  join employee e on d.number = e.serial_no
  where e.nic=893041699; //example for nic number 893041699

显示类似

的输出
designation
------------
Helper

答案 2 :(得分:0)

Select * from employee a, designation b where a.serial_no = b.number and a.nic=921560419

答案 3 :(得分:0)

试试这个:

select e.*, d.designation AS desi_name FROM employee AS e LEFT JOIN designation AS d ON e.serial_no=d.number

你进入desi_name