Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to return static strings in MySQL?
In order to return static strings in MySQL, you can use UNION. Following is the syntax −
select 'yourStringValue1' as yourAliasName UNION select 'yourStringValue2' as yourAliasName;
Let us implement the above syntax to return static strings in MySQL. Following is the query −
mysql> select 'HELLO' as staticStringsResult -> UNION -> select 'MySQL' as staticStringsResult;
This will produce the following output −
+---------------------+ | staticStringsResult | +---------------------+ | HELLO | | MySQL | +---------------------+ 2 rows in set (0.00 sec)
In some MySQL versions, the above syntax does not work, therefore you need to wrap up with parenthesis −
mysql> (select 'HELLO' as staticStringsResult) -> UNION -> (select 'MySQL' as staticStringsResult);
This will produce the following output −
+---------------------+ | staticStringsResult | +---------------------+ | HELLO | | MySQL | +---------------------+ 2 rows in set (0.00 sec)
Advertisements
