PHP Tutorials
- What is MySqli
- mysql query
- mysql query example
- InnoDB
- mysql column Type
- CRUD Example
- Connection Using Function
- mysql keys
- SELECT
- WHERE
- UPDATE
- Count no of Rows
- ALIAS
- AND, AND & OR
- BETWEEN
- COMPARISON OPERATOR
- DELETE
- DELETE LIMIT
- DISTINCT
- EXISTS
- FROM
- GROUP BY
- HAVING
- IN
- INTERSECT
- IS NULL & IS NOT NULL
- LIKE
- NOT
- ORDER BY
- SELECT LIMIT
- SUBQUERY
- TRUNCATE
- UNION && UNION ALL
- Concat & Group_Concat
- mysql Function
- Mysql Insert Id
- MySql Aggregate Function
- Mysql Join
- JOIN in MySql
- Trigger
- Procedure
- Transaction
- views
- Index
- SQL Injection
- Normalization
- Query Bind
- Interview Questions
Important Link
what is CONCAT()?
CONCAT function is a String function, which is used to merge two or more strings and return a single string value. Example:-
SELECT CONCAT("ittutorial ", "is ", "a ", "best ","tutorial") AS Concatenated_String;
output :-
ittutorial is a best tutorial
Example
SELECT CONCAT(Name, " ", address, " ", City) AS Address FROM itechxpert;
SELECT Name, CONCAT(Address, " ", pincode, " ", City) AS Address FROM itechxpert;
GROUP_CONCAT()
GROUP_CONCAT() is a type of an aggregate function. This function is used to concatenate string from multiple rows into a single string using various clauses. If the group contains at least one non-null value, it always returns a string value. Otherwise, you will get a null value.
SELECT cust_id, cust_fname, cust_lname, dept_id,
GROUP_CONCAT(designation) as "designation"
FROM customer group by cust_id;
Using DISTINCT Clause
SELECT cust_fname, cust_id,
GROUP_CONCAT(DISTINCT designation) as "designation"
FROM customer group by cust_id;
Using Separator Clause
File Name :
SELECT emp_fname,
GROUP_CONCAT(DISTINCT designation SEPARATOR '; ') as "designation" FROM employee group by emp_id;
Example
File Name :
SELECT Id, Department, CONCAT(FirstName, ‘ ‘ , LastName) AS Fullname FROM Employee;