从id重复的表中获取所有行

时间:2017-07-03 09:57:28

标签: php mysql

+------+---------+----------+
| id   | uid     | assessors|
+------+---------+----------+
|    1 | 1       | Volvo    | 
|    2 | 2       | kenitra  | 
|    3 | 3       | rabat    |
|    4 | 3       | Fahad    |
|    5 | 3       | John     | 
+------+---------+----------+

我想在uid的基础上获取数据,因为我使用内部联接从其他表中获取数据现在我想获取并显示uid上的所有数据但我得到此输出

+---------+----------+
| uid     | assessors|
| 1       | Volvo    | 
| 2       | kenitra  | 
| 3       | rabat    |

所需的输出是:

+---------+----------+
| uid     | assessors|
| 1       | Volvo    | 
| 2       | kenitra  | 
| 3       | rabat    |
| 3       | Fahad    |
| 3       | John     |  

我的查询是=

SELECT * FROM lego_activity_answers WHERE uid = $studentid;

$ studentid来自另一个表

2 个答案:

答案 0 :(得分:0)

如果您希望获取lego_activity表格中除id之外的所有数据,只需选择所需的各个字段,而不是查询*

SELECT uid, assessors FROM lego_activity_answers WHERE uid = $studentid;

答案 1 :(得分:0)

SELECT DISTINCT uid,评估员来自lego_activity_answers,其中uid = $ studentid;

(这可能在大型表格中表现不佳)