简体   繁体   English

将两个不同的sql表与具有相同数据的列联接在一起

[英]Join two different sql tables with columns that have the same data

I have two different sql statements I'm executing and one works and the other one semi works if I remove the ambiguous column. 我有两个正在执行的不同的sql语句,如果删除不明确的列,则一个有效,另一个有效。 Is there a way to specify which columns I want to grab information from on both tables? 有没有一种方法可以指定我要从两个表中获取信息的列?

select * from currentprojects
     Join Group on Group.projectcode= currentprojects.projectcode

This is the first statement and it works but when the table is displayed the whole page breaks. 这是第一个语句,它有效,但是显示表时整个页面都会中断。

SELECT 
   name,
   projectid,
   projectcode,
   completiondate,
   meeting,
   status
FROM currentprojects
Join Group on Group.status= currentprojects.projectcode

The second statement works if I remove projectcode from the query, but I want to have both datasets showing different things. 如果我从查询中删除项目代码,则第二条语句有效,但是我希望两个数据集都显示不同的内容。

try this. 尝试这个。 Aliasing helps once your queries start getting pretty dense 一旦查询开始变得密集起来,别名便会有所帮助

 SELECT cp.Cloumn, g.Column 
 FROM currentprojects cp
 INNER JOIN Group g ON g.projectcode= cp.projectcode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM