
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Is there any alternative for CONCAT() in MySQL?
Yes, an alternative is CONCAT_WS(). Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) ); Query OK, 0 rows affected (0.74 sec)
Example
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | Bob | +-----------+-------------+ 3 rows in set (0.00 sec)
Let us see how to work with an alternative of CONCAT() in MySQL −
mysql> select concat_ws(SPACE(2), 'Student Name is:',StudentName) from DemoTable;
Output
+-----------------------------------------------------+ | concat_ws(SPACE(2), 'Student Name is:',StudentName) | +-----------------------------------------------------+ | Student Name is: Chris | | Student Name is: Robert | | Student Name is: Bob | +-----------------------------------------------------+ 3 rows in set (0.04 sec)
- Related Articles
- Is there any alternative for OpenCV imshow() method in Java?
- Is there any alternative solution for static constructor in java?
- Implement MySQL query using multiple OR statements. Any optimal alternative?
- Name two alternative arrangements for sewage disposal where there is no sewerage system.
- Working with MySQL WHERE.. OR query with multiple OR usage. Is there an alternative?
- Is there any precautionary medicine available for Dengue?
- Is their any alternative to HTML5 iframe srcdoc?
- Is there any whoami function or command in MySQL like UNIX?
- Which is the JavaScript RegExp to find any alternative text?
- Alternative to MySQL CASE WHEN in MySQL
- Is there a naming convention for tables in MySQL?
- Are there any certification exams available for Python?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- Concat a field in MySQL SELECT?
- Is there any easy way to add multiple records in a single MySQL query?

Advertisements