I was wondering if I could select given values from a list and populate rows? For example, SELECT 1 as one, 2 as two, 3 as three
will populate columns:
one | two | three
------------------------
1 | 2 | 3
I'm looking for a script that populates rows, something like:
values
-------
1
2
3
4
Thanks!
mysql> select *from ListOfValues where Age IN(20,21,23,25,26,27,28) -> order by field(Age,20,21,23,25,26,27,28); The following is the output.
A list of commonly used MySQL queries to create database, use database, create table, insert record, update record, delete record, select record, truncate table and drop table are given below.
The MySQL GROUP BY Statement The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.
Description. := Assign a value. = Assign a value (as part of a SET statement, or as part of the SET clause in an UPDATE statement)
you can union each one if you want like so
SELECT 1 AS numbers
UNION SELECT 2
UNION SELECT 3
a much simpler way to do something like this would be to make a table with an auto incremented id... insert into another column in the table an empty string... then just select the auto incremented id
CREATE TEMPORARY TABLE tmp (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
val varchar(1)
);
INSERT INTO tmp (val)
values
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
("");
select id from tmp;
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With