MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
1PLs Company - #1Payday.Loans Agency - Loans online and near me $100-$2500 (Same Day)
Powered by MySQL
 
Home / Tricky Select Queries / Question No: 53

How to retreive multiple records without a reference table?

I want to use a select statement to retrieve multiple records without a reference table. Obviously it is easy to retrieve a single record is simple enough:
SELECT 'val_1' AS var1, 'val_2' AS var2;

+--------+--------+
| var1 | var2 |
+--------+--------+
| val_1 | val_2 |
+--------+--------+
But I need to produce multiple records without referencing any tables:
+--------+--------+
| var1 | var2 |
+--------+--------+
| val_1 | val_2 |
| val_3 | val_4 |
| val_5 | val_6 |
+--------+--------+

Answer No: 53

To retrieve multiple records without a reference table, you can use UNION operator provided by MySQL. It may serve your goal.  Take an example:
SELECT  'val_1' AS var1,  'val_2' AS var2 
UNION
SELECT 'val_3' AS var1, 'val_4' AS var2
UNION
SELECT 'val_5' AS var1, 'val_6' AS var2;

Related MySQL FAQs to the Above FAQ

How-to-do-numeric-sorting-within-a-string-field-in-MySQL How to do numeric sorting within a string field in MySQL?

How-to-take-data-back-up-of-single-table How to take data back up of single table?

How-to-find-duplicate-records-from-a-table-in-MySQL How to find duplicate records from a table in MySQL?

How-to-get-last-top-records-in-asceding-order How to get last top records in asceding order?

How-to-move-table-from-one-to-another-MySQL-database How to move table from one to another MySQL database?

How-to-get-parent-table-child-table-and-grandchild-table-aggregates-in-MySQL How to get parent table child table and grandchild table aggregates in MySQL?

How-to-skip-repeating-values-from-the-query-results How to skip repeating values from the query results?

How-to-retrieve--one-child-row-against-each-parent-id How to retrieve one child row against each parent id?

An-important-trick-to-speed-up-select-query An important trick to speed up select query.

How-to-find-the-books-which-have-authors-with-more-than-one-book-in-the-table How to find the books which have authors with more than one book in the table?

How-to-count-the-number-of-rows-containing-APOSTROPHE-in-MySQL How to count the number of rows containing APOSTROPHE in MySQL?

How-to-compare-data-of-two-tables-of-two-different-databases-in-MySQL How to compare data of two tables of two different databases in MySQL?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2024  www.mysqlfaqs.net
All rights reserved.