Select all columns that are not null?

Discussion in 'MySQL' started by frobak, Feb 21, 2012.

  1. #1
    Hi

    I have a database table, each row contains lots of columns, only 1 column per row will have a value.

    Is there a way to get the column that has a value without having to list every column name in the query?

    For example:

    
    SELECT * 
    FROM table 
    WHERE YourColumn IS NOT NULL
    
    Code (markup):
    I dont really want to list all the columns in the table if i dont have to? Is there a way?

    Cheers
     
    frobak, Feb 21, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You would have to do some sort of stored procedure and/or nested query to get the actual columns that are null. This would be very complicated if it's even possible.
     
    jestep, Feb 21, 2012 IP
  3. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Sounds like your table isn't normalized. I'd look into properly structuring your database. What is the actual table structure? (i.e. field names and types?)
     
    plog, Feb 21, 2012 IP