The above query has used GROUP_CONCAT() function to concatenate all the sale_department values for salesperson Henry and George.Sale_person_name IN ('Henry', 'George') Since we are using a DISTINCT clause, the query is not returning the duplicate values.Įxample3: Select all the sale departments in a single field from the sale_details table only for Henry and George.The above query has used GROUP_CONCAT() function to concatenate all the sale_department values in the sale_details table.Since we are using a GROUP BY clause, the query returns the result for each salesperson.Įxample2: Select all the sale departments in a single field from the sale_details table.The NULL value from the sale_department table is not a part of the final result.The above query used the GROUP_CONCAT() function to concatenate all sale_department values for which a salesperson is working separated by a ‘.’.We will be looking into a few examples to have a better understanding of the concept.Įxample1: Select all the sales departments for each salesperson from the sale_details table. To view the snapshot of the sale_details table, execute: SELECT * FROM sale_details INSERT INTO sale_details (id,sale_person_id,sale_person_name,no_products_sold,sales_department) We will be creating a table sale_details followed by inserting a few rows into it. Let us get started by making the sample data. This function will return the result ignoring the NULL values. GROUP_CONCAT(expression) will return the concatenated values from a group. We will be using the GROUP_CONCAT() function of MySQL in the below examples. We can also say that we want to see the results from the MySQL query into a single-row column. This article will see how to concatenate the MySQL query results from multiple rows into a single field through many examples. Remove First and Last elements from Python List.Remove elements from List using pop() method in Python. ![]() ![]() ![]() Remove element with Maximum value in Python List.Looking for Something Search for: Search Recent Posts
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |