Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select static values column?

Tags:

select

mysql

When we run query SELECT 1 then MySQL returns one row with one column containing 1. How should I build the query to get one column with several rows containing specified values? I think it can be something like SELECT VALUES(1,2,3) AS v?

like image 416
WindBridges Avatar asked Nov 20 '13 16:11

WindBridges


People also ask

How do you select a column by value?

Click the top edge of the column header or the column in the table. The following selection arrow appears to indicate that clicking selects the column. Note: Clicking the top edge once selects the table column data; clicking it twice selects the entire table column.

How do you select a column with multiple values?

Note – Use of IN for matching multiple values i.e. TOYOTA and HONDA in the same column i.e. COMPANY. Syntax: SELECT * FROM TABLE_NAME WHERE COLUMN_NAME IN (MATCHING_VALUE1,MATCHING_VALUE2);

How do I add a constant to a column in SQL?

You can add static value when you use INSERT INTO SELECT MySQL query. Write the value directly in the select statement or you can add with the help of variable which initializes the value. SET @yourVariableName − = yourstaticValue; INSERT INTO yourSecondTableName(yourColumnName1,yourColumnName2,....

How do I select part of a column?

Or click on any cell in the column and then press Ctrl + Space. Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.


1 Answers

Union is usually the quick way to create a defined set of values in a single data set

SELECT 1 as Value
UNION
SELECT 2 as Value
UNION
SELECT 3 as Value

If this is going to have lots of values, then building a tally/number table might be a more preferable method. Creating a "Numbers Table" in mysql

like image 121
Steph Locke Avatar answered Sep 18 '22 00:09

Steph Locke