WebDevelopersNotes logo

home-icon Home / MySQL / A little more on the MySQL SELECT statement

A little more on the MySQL SELECT statement

A little more on the MySQL SELECT statement

The MySQL SELECT command is something like a print or write command of other languages. You can ask it to display text strings, numeric data, the results of mathematical expressions etc.

Displaying the MySQL version number

select version();

+-----------+
| version() |
+-----------+
| 3.22.32   |
+-----------+
1 row in set (0.00 sec)

Displaying the current date and time

select now();

+---------------------+
| now()               |
+---------------------+
| 2001-05-31 00:36:24 |
+---------------------+
1 row in set (0.00 sec)

Displaying the current Day, Month and Year

SELECT DAYOFMONTH(CURRENT_DATE);
+--------------------------+
| DAYOFMONTH(CURRENT_DATE) |
+--------------------------+
|                       28 |
+--------------------------+
1 row in set (0.01 sec)

SELECT MONTH(CURRENT_DATE);
+---------------------+
| MONTH(CURRENT_DATE) |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

SELECT YEAR(CURRENT_DATE);
+--------------------+
| YEAR(CURRENT_DATE) |
+--------------------+
|               2001 |
+--------------------+
1 row in set (0.00 sec)

Displaying text strings

select 'I Love MySQL';

+--------------+
| I Love MySQL |
+--------------+
| I Love MySQL |
+--------------+
1 row in set (0.00 sec)

Obviously you can provide pseudo names for these columns using AS.

select 'Manish Sharma' as Name;

+---------------+
| Name          |
+---------------+
| Manish Sharma |
+---------------+
1 row in set (0.00 sec)

Evaluating expressions in MySQL

select ((4 * 4) / 10 ) + 25;

+----------------------+
| ((4 * 4) / 10 ) + 25 |
+----------------------+
|                26.60 |
+----------------------+
1 row in set (0.00 sec)

Concatenating in MySQL

With SELECT you can concatenate values for display. CONCAT accepts arguments between parenthesis. These can be column names or plain text strings. Text strings have to be surrounded with quotes (single or double).

SELECT CONCAT(f_name, " ", l_name)
from employee_data 
where title = 'Programmer';

+-----------------------------+
| CONCAT(f_name, " ", l_name) |
+-----------------------------+
| Fred Kruger                 |
| John MacFarland             |
| Edward Sakamuro             |
| Alok Nanda                  |
+-----------------------------+
4 rows in set (0.00 sec)

You can also give descriptive names to these columns using AS.

select CONCAT(f_name, " ", l_name)
AS Name
from employee_data
where title = 'Marketing Executive';

+---------------+
| Name          |
+---------------+
| Monica Sehgal |
| Hal Simlai    |
| Joseph Irvine |
+---------------+
3 rows in set (0.00 sec)

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Internet Explorer jokes and funny images

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

In an attempt to push sales of its digital books, Amazon, offers the Kindle application which runs on a variety of platforms, both desktop and mobile. This is in addition to their hardware Kindle e-book readers. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy