[英]sql concat columns from different tables
I'm looking to create a view that concatenates two columns from two tables together. 我正在寻找创建一个视图,将两个表中的两列连接在一起。 the scenario is as follows: 方案如下:
Table1 - Parent 表1 - 父
Id
fname
lname
age
Table2 – child 表2 - 孩子
Id
parent_id
fname
age
view – child 视图 - 孩子
Id
firstlast
age
Given that the child table has a fk reference to parent's ID, and parent has a lname column that I'm interested in, how would one create a view that contains 鉴于子表有一个对父ID的fk引用,而parent有一个我感兴趣的lname列,如何创建一个包含的视图
child(id), 孩子(ID),
child(fname)
. child(fname)
。 . 。
parent(lname)
as fullname parent(lname)
as fullname
child(age) 儿童(年龄)
the fullname would appear 'Jimmy Smith' 全名出现'吉米史密斯'
Try the following :- 请尝试以下方法: -
select c.id, concat(c.fname, p.lname) as full_name from
parent p
inner join
child c
on p.id = c.parent_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.