tags:

views:

15

answers:

2

Hello All

A little confused how to create a query and set a dynamic var in the query for output.

Lets say I have a basic table with the following

id | name | type | location

Now I want to do a query and select all data pretty simple stuff

SELECT * FROM TABLE

Which will give me ie.

1 | batman | scifi | row a
2 | matrix | scifi | row b

Bit I want to add a dynamic row to tell me its a video. ie

id| name   | type  | location | category
1 | batman | scifi | row a    | video
2 | matrix | scifi | row b    | video

How can I add this to a query ??

Hope someone can advise!!

Thank you in advance

A: 

SELECT *, 'video' category FROM table

That will add a category column that has a value of video for all rows. Is this what you meant?

Tatu Ulmanen
Does not work ?
Lee
Yes it does? How does it not work?
Tatu Ulmanen
@tatu: you're missing the AS keyword.
longneck
Some databases do not require the AS keyword. Not sure about mysql (which the OP tagged)
Joe
At least MySQL 5 does not need it.
Tatu Ulmanen
+1  A: 
SELECT  *, 
        'video' AS category
FROM    TABLE
Maximilian Mayerl
Now i feel really dumb !! Works a charm
Lee