Reputation: 84
i have a view in mysql and i want to show two rows with the same id in one row. Please see following pic :
please help me : i want to show expr1 column in one column
Upvotes: 2
Views: 8110
Reputation: 18747
Use GROUP_CONCAT
:
SELECT POST_ID,TITLE,USERNAME,DATE_TIME,COMMENT_COUNT,GROUP_CONCAT(Expr1) as Expr1
FROM TableName
GROUP BY POST_ID,TITLE,USERNAME,DATE_TIME,COMMENT_COUNT
Result will be:
POST_ID TITLE USERNAME DATE_TIME COMMENT_COUNT Expr1
1 HELLO WORLD AMIN 2014-01-01 00:00:00.000 0 OS,windows xp
Upvotes: 5
Reputation: 24002
As it seems data in all other columns are matching, grouping by id
may work.
But it is always suggested to group by
those columns that are chosen in select
select
post_id, title,
username, date_time,
comment_count,
group_concat( expr1 separator ' ' ) Expr1
from table_name
group by 1, 2, 3, 4, 5 -- positions of columns in the select
Upvotes: 0