[英]join of two sql tables
I have two tables and I want to join them to get the desired output.我有两个表,我想加入它们以获得所需的输出。 Say the 1st table (seat1) is
说第一张桌子(seat1)是
and the 2nd table (collegestudents) is第二张桌子(大学生)是
The desired output is所需的输出是
I have tried the below code.我试过下面的代码。 But it fails to give the desired result.
但它没有给出想要的结果。
$rde2=mysqli_query($con, "select * from seat1 s
left JOIN collegestudents c ON c.Roll = s.Roll
");
Any help please.
You want a left join
.你想要一个
left join
。 Your query looks fine, but you would need not to use select *
, and instead explictly list the columns that you want to select, using table prefixes.您的查询看起来不错,但您不需要使用
select *
,而是使用表前缀明确列出要选择的列。 Otherwise, since you have a Roll
column in both tables, a name clashes will happen, that your application apparently does not handle well.否则,由于您在两个表中都有一个
Roll
列,因此会发生名称冲突,您的应用程序显然不能很好地处理。
select
s.Roll,
c.Name,
s.Subject
from seat1 s
left join collegestudents c on c.Roll = s.Roll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.