Add column to mysql query plus give it value

I'm not sure how to do this, but I have a query that has alliances. and I want to be able to distinguish each of them by adding a column. How to add this column and give it a value. Thank!

Select ID,Name,SpecialColumn = 'Test'
from table where ID = 'guid';
+5
source share
1 answer

Use a string literal followed by a column alias 'Test' AS SpecialColumn. This will result in the same value for all returned rows, useful for differentiating between components UNIONor filling in inappropriate column numbers between components UNIONwhen necessary.

SELECT
  ID,
  Name,
 'Test' AS SpecialColumn
FROM table
WHERE ID = 'guid';

The output (ignoring your where clause) would be something like this:

ID  Name     SpecialColumn
--------------------------
1   Venkman  Test
2   Egon     Test
1   Winston  Test
3   Ray      Test
+7

All Articles