Forum Moderators: open

Message Too Old, No Replies

Select all fields from database with value > "0"

         

poisontheused

12:14 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Hi,

Hoping a guru can help me out on this one, I have 1 database table where i am storing my form data.

short example of my database row below.

item1 item2 item3 item4
----- ----- ----- -----
--0-- --3-- --2-- --0--

Using a SELECT statement I want to be able to retrieve the values of all the fields from this database row that have a value > 0. Is this possible? in my past mysql work i've just used basic SQL SELECT statements, so this one is causing me a bit of trouble.

If anyone has any ideas how this can be achieved, it would be much appreciated.

FalseDawn

1:40 am on Apr 27, 2007 (gmt 0)

10+ Year Member



You would be better off with a 2 column table like:
[Item Name] [Item Value]
item1 0
item2 3
item3 2
item4 0

etc

SQL is row(set)-based and is not really meant to retrieve values from fields based on the value in those fields.

phranque

5:28 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can select all rows where at least one of the fields is >0 but you cannot select just the valuated fields per row.