DEV Community

Ashok Kumar
Ashok Kumar

Posted on

concat() vs Group_concat()

πŸš€ SQL – CONCAT() vs GROUP_CONCAT()

When I started learning SQL, I got confused between CONCAT and GROUP_CONCAT. Both look similar, but their usage is very different. Here’s a simple breakdown with examples πŸ‘‡

πŸ”Ή CONCAT()

Combines column values within the same row.

Example: Joining first_name + last_name β†’ NICK WAHLBERG

Works only at row-level.
πŸ“Έ (Refer first image)

πŸ”Ή GROUP_CONCAT()

Combines values from multiple rows into a single string.

Example: Grouping all cate_id values for each pub_id.

Usually used with GROUP BY.
πŸ“Έ (Refer second image)

⚑ Key Difference:

Use CONCAT β†’ row-wise string merge.

Use GROUP_CONCAT β†’ row aggregation into one string.

πŸ’‘ This is a common interview question. Beginners in SQL often confuse these two, so keeping this clear helps in both projects + interviews.


πŸ‘‰ If you’re learning SQL, what other functions confuse you? Let’s discuss!

SQL #Database #DataAnalytics #Learning


Top comments (0)