Syntax error Using backticks in CONTACT() gives an error in MySQL

Using backticks in CONTACT() gives an error in MySQL



Do not use backticks, you can use single quotes in CONCAT(). Following is the syntax −

select concat(yourColumnName1,' ',yourColumnName2) from yourTableName;

Let us first create a table −

mysql> create table DemoTable1359
    -> (
    -> Id int,
    -> Name varchar(20)
    -> );
Query OK, 0 rows affected (0.58 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1359 values(101,'Chris');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1359 values(102,'Adam');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1359 values(103,'Mike');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1359 values(104,'John');
Query OK, 1 row affected (0.20 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1359;

This will produce the following output −

+------+-------+
| Id   | Name  |
+------+-------+
|  101 | Chris |
|  102 | Adam  |
|  103 | Mike  |
|  104 | John  |
+------+-------+
4 rows in set (0.00 sec)

Here is the query to use single qotes in CONTACT() −

mysql> select concat(Id,' ',Name) from DemoTable1359;

This will produce the following output −

+---------------------+
| concat(Id,' ',Name) |
+---------------------+
| 101 Chris           |
| 102 Adam            |
| 103 Mike            |
| 104 John            |
+---------------------+
4 rows in set (0.00 sec)
Updated on: 2019-11-08T10:35:10+05:30

152 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements