Is it possible say for example i want to select a column which does not exist in an mysql table, i just want this column to have incremental values starting from "somevalue (100 maybe)". I want something like this:
my dummy column | other existing columns | blah
100
101
102
is this possible in mysql?
Yes sure, You can named column with as
keyword. For example:
SELECT 1 as 'hello'
And You can simply add RowNumber column like below example:
SELECT t.*,
@rownum := @rownum + 1 as RowNumber
FROM your_table t,
(SELECT @rownum := 0) r
For start from
149
, You just need to replace(SELECT @rownum := 0)
with(SELECT @rownum := 149)
For a dummy column with the certain type, Use
Cast
orConvert
functions like this:CAST(@rownum := @rownum + 1 AS CHAR) AS RowNumber
. You can find more about this here: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
More Examples related to the comments:
SELECT
COUNT(col1) AS col2
FROM your_table
GROUP BY col2
HAVING col2 = 2;
@nodsdorf example in the comments:
SELECT
(1+1) AS dummy,
other_column
FROM table
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