Jump to content

Recommended Posts

I created this select query to get some rows... Its working. but my problem is I need to remove duplicate rows from the query...

 

this is my query:

 

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%';

 

This is its output:

 

+----------+-------------+------------+-------------------------------+-----------------------+------------+

| tutor_id | category_id | subject_id | subjects | tutor_name | tutor_code |

+----------+-------------+------------+-------------------------------+-----------------------+------------+

| 1 | 6 | 37 | Business Studies | Tharanga Nuwan Kumara | 1250 |

| 3 | 6 | 37 | Business Studies | Kumara | 1252 |

| 15 | 4 | 11 | Business & Accounting Studies | Tharanga Nuwan Kumara | 1264 |

| 15 | 6 | 37 | Business Studies | Tharanga Nuwan Kumara | 1264 |

| 16 | 5 | 11 | Business & Accounting Studies | Kasun Kalhara | 1265 |

| 16 | 6 | 37 | Business Studies | Kasun Kalhara | 1265 |

+----------+-------------+------------+-------------------------------+-----------------------+------------+

 

 

 

Here, you can see tutor id has duplicated in my query. and I need to select all subjects to a tutor in one row separated by comma.

 

eg: (Business & Accounting Studies, Business Studies) like this..

 

So can anybody tell me what I need to do in my select query??

 

Thank you.

Edited by thara
Link to comment
https://forums.phpfreaks.com/topic/270108-problem-in-my-select-query/
Share on other sites

SELECT

tcs.tutor_id,

tcs.category_id,

tcs.subject_id,

GROUP_CONCAT(s.subjects SEPARATOR ',') AS 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%'

GROUP BY tcs.tutor_id;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.