1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

selecting column names

Discussion in 'Databases' started by neilfurry, Dec 21, 2017.

  1. #1
    hi Mate,

    i need help on this,

    how can i select column names instead of its value, so it looks like this

    SELECT COLUMN_NAME WHERE row='002452' AND COLUMN_NAME IS NULL

    so it will display those NULL columns.

    row is the location of the id of an employee
    SEMrush
    Hope to get help on this.

    Cheers!

    Neil
     
    neilfurry, Dec 21, 2017 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    24,149
    Likes Received:
    3,256
    Best Answers:
    92
    Trophy Points:
    615
    #2
    Are you wanting to know which columns have no value?
     
    sarahk, Dec 22, 2017 IP
  3. phpmillion

    phpmillion Member

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    35
    #3
    You can't select only column names because it would not make any sense. In other words, when you select something from column name, you need to enter the name of this column. So take a look at your query:

    SELECT COLUMN_NAME WHERE row='002452' AND COLUMN_NAME IS NULL

    This is what you do: you are trying to select the name of column when you already know the name. It's just not logical. Not to mention that you need to select by columns, not by rows; therefore, WHERE row='002452' doesn't make any sense (and will never work) too.

    Here's the basic tutorial that should be useful to you during your learning steps - http://www.mysqltutorial.org/mysql-select-statement-query-data.aspx
     
    phpmillion, Dec 22, 2017 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    24,149
    Likes Received:
    3,256
    Best Answers:
    92
    Trophy Points:
    615
    #4
    I guess you could do

    select *
    from `my_table`
    where `name` is null
    or `type` is null
    or `colour` is null


    and so on

    and then in your script you decide what to do

    You could do some of the sorting in the database, this will only show up the first problem field but you'll get the idea

    select *, case when `name` is null then 'name' else case when `type` is null then 'type' else case when `colour` is null then 'colour' end

    have a look at http://sqlfiddle.com/#!9/63e399/5 for a working example
     
    sarahk, Dec 22, 2017 IP