What does parenthesis mean in MySQL SELECT (COLNAME)?


The SELECT(COLNAME) means, we are creating an alias for that column. Let us see an example and create a table −

mysql> create table DemoTable865(
   FirstName varchar(100),
   LastName varchar(100)
);
Query OK, 0 rows affected (0.77 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable865 values('Chris','Brown');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable865 values('Adam','Smith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable865 values('David','Miller');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable865 values('Carol','Taylor');
Query OK, 1 row affected (0.15 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable865;

This will produce the following output −

+-----------+----------+
| FirstName | LastName |
+-----------+----------+
| Chris     | Brown    |
| Adam      | Smith    |
| David     | Miller   |
| Carol     | Taylor   |
+-----------+----------+
4 rows in set (0.00 sec)

Here, we are creating an alias for the column with SELECT (COLNAME) MySQL −

mysql> select (FirstName) StudentFirstName,(LastName) StudentLastName from DemoTable865;

This will produce the following output −

+------------------+-----------------+
| StudentFirstName | StudentLastName |
+------------------+-----------------+
| Chris            | Brown           |
| Adam             | Smith           |
| David            | Miller          |
| Carol            | Taylor          |
+------------------+-----------------+
4 rows in set (0.00 sec)

Updated on: 03-Sep-2019

273 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements