- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
To Continue Learning Please Login
Login with Google