我创建了这个选择查询来获取一些行......它的工作。但我的问题是我需要从查询中删除重复的行...
这是我的查询:
SELECT tcs.tutor_id, tcs.category_id, tcs.subject_id, s.subjects, t.tutor_name, t.tutor_code
FROM tutor_category_subject as tcs
INNER JOIN subject AS s ON tcs.subject_id = s.subject_id
INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id
WHERE s.subjects LIKE '%business%';
这是它的输出:
+----------+-------------+------------+------------------+-------------------+-----------+
| tutor_id | category_id | subject_id | subjects | tutor_name | tutor_code|
+----------+-------------+------------+------------------+-------------------+-----------+
| 1 | 6 | 37 | Business Studies | Tharanga Nuwan | 1250 |
| 3 | 6 | 37 | Business Studies | Kumara | 1252 |
| 15 | 4 | 11 | Business & Accou | Tharanga Nuwan | 1264 |
| 15 | 6 | 37 | Business Studies | Tharanga Nuwan | 1264 |
| 16 | 5 | 11 | Business & Accou | Kasun Kalhara | 1265 |
| 16 | 6 | 37 | Business Studies | Kasun Kalhara | 1265 |
在这里,您可以看到导师 ID 在我的查询中重复。我需要在一行中选择导师的所有科目,以逗号分隔。
例如:(商业与会计研究,商业研究)像这样..
那么有人可以告诉我在我的选择查询中我需要做什么吗?
谢谢你。
这是我期待的结果
+----------+-------------+------------+-------------------------------------------------+-----------------------+------------+
| tutor_id | category_id | subject_id | subjects | tutor_name | tutor_code |
+----------+-------------+------------+-------------------------------------------------+-----------------------+------------+
| 16 | 5 | 11 | Business & Accounting Studies, Business Studies | Kasun Kalhara | 1265 |
| 3 | 6 | 37 | Business Studies | Kumara | 1252 |
| 1 | 6 | 37 | Business Studies, Business & Accounting Studies | Tharanga Nuwan Kumara | 1250 |
+----------+-------------+------------+-------------------------------------------------+-----------------------+------------+