SQL for make new colom but only 1 value for all row

Issue

I want to add new category column and fill it with one same value for all row but I can not do query update for some reason.

I am hoping that my table will be like this:

---------------------
no | Name | Category |
1  | A    |   1      |
2  | B    |   1      |
3  | C    |   1      |
4  | D    |   1      |
----------------------

Solution

You don’t really need an update here if your goal be to simply view your data this way. In that case, just select a constant value for the category:

SELECT no, Name, 1 AS Category
FROM yourTable
ORDER BY no;

Answered By – Tim Biegeleisen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published