2013-10-11 282 views
-5

请有人可以帮我写一个SQL查询。我不知道,但我只是需要它来快速修复。需要帮助写一个SQL查询

我是想这样的事情:

select college.colg_id, 
     college.student_id, 
     student.student_name from college, 
     student  
     where college.student_id=student.student_id; 

这给了我这我不知道所有数据。

colg_id student_id 
1   1 
1   2 
1   3 
1   4 
2   5 
2   6 

student_id student_name 
1   a1 
2   b1 
3   c1 
4   d1 
5   e1 
6   f1   

我只需要数据的

colg_id | student_id | student_name. 
+1

形式我想帮助,但请格式化你的问题有点...我无法理解你想达到什么.. –

+0

是现在清除....我从Excel中复制它。我不知道它是如何在一行。如果我用简单的话来说明我的问题,我只想在college表的输出中添加student_name。每个名字都显示与他们各自的student_id – user2696466

回答

2
SELECT c.colg_id, c.student_id, s.student_name FROM college c 
LEFT JOIN student s ON s.student_id = c.student_id 
+0

相同的结果作为我的... – user2696466