Carl Yi Carl Yi - 1 month ago 5
MySQL Question

Same output for same data in GROUP_CONCAT()

i need two subqueries in one sql query
one of the results maybe is '1,3,2' and the other one is '1,2,3'
how could i judge this two results are equals
i really really need they are equals...

two subqueries are sql

SELECT t.project_id,GROUP_CONCAT(t.type,',') AS seg_type FROM
t_project_bid_announce_draft t WHERE t.project_id = '6639124947eb4e0cafc054b9ddcf9f54'


and sql

SELECT p.segment_type FROM t_project_segment p WHERE p.project_id =
'6639124947eb4e0cafc054b9ddcf9f54'

Answer

Use order by:

SELECT t.project_id,
       GROUP_CONCAT(t.type ORDER BY t.type SEPARATOR ',' ) AS seg_type
FROM t_project_bid_announce_draft t
WHERE t.project_id = '6639124947eb4e0cafc054b9ddcf9f54'