Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL multiple row literal select [duplicate]

Tags:

mysql

Possible Duplicate:
Can you define “literal” tables in SQL?

Occasionally I find myself in a situation where I'd like to join an existing table to a table of values that are entered in the query. Something like:

SELECT ((1,2,3),(4,5,6)); 

Where the query would return two rows of 3 columns. Obviously this syntax is not correct, but it is possible to generate a single row of data in this way. For example:

SELECT 1,2,3;

Is there actually a way to do what I'm trying to achieve?

like image 244
andrewmabbott Avatar asked Oct 28 '11 10:10

andrewmabbott


People also ask

How to select all duplicate MySQL rows based on one or two columns?

Select all duplicate MySQL rows based on one or two columns? For this, use subquery along with HAVING clause. Let us first create a table − Following is the query to select all duplicate rows based on one or two columns.

How to select multiple rows in one query with multiple conditions?

mysql - Selecting Multiple Rows in One Query with Multiple Conditions - Database Administrators Stack Exchange I can select multiple rows with one condition by using something like: SELECT `Col`, `Col2` FROM `Table` WHERE `Col3` IN (?, ?, ?, ?, ?);

How many rows can I select in a single query?

A single query will select from 10 to 100 rows (though most of the time it'll be only 10)- it has to be fast in terms of performance. This is why using multiple queries isn't a good idea. The CREATE TABLEstatement is:

What is the correct way to select multiple rows?

What is the correct way to select multiple rows? fetch_row () does exactly what its name suggests: it fetches a single ROW. You're looping on the individual fields in that row. Use a while loop with your myslqi_fetch_row () function.


1 Answers

SELECT 1,2,3
UNION ALL
SELECT 4,5,6;
like image 82
gbn Avatar answered Oct 04 '22 16:10

gbn