Select query ignoring certain columns

  • Is it possible?

    I have one table with 35 columns. I want to write a select statement which should display data of all columns expect some columns (e.g. column 2,4 and 10).

  • Sure... what's the problem? Only those columns that you name in the SELECT will be returned.

    If you are asking whether you can write SELECT * FROM .... and exclude some columns, you can't - and it is a bad idea anyway. You should not use SELECT * at all - well, with a few exceptions, one of them being WHERE EXISTS (SELECT * ...); I also sometimes use SELECT * FROM view, because the view already contains only those columns that need to be returned. Otherwise, the * is not best practice.

  • It's not possible. You should explicitly mention the column names you want:

    Select column 1, column2, column 5, column 7

    From...

    That's also a best practice.

    Warm Regards,
    Neel aka Vijay.

  • My query is for example if you have a table with column named from a to z. I want to display all columns expect b,e,f.

    Instead to writing all columns like

    Select a,c,d,g,h,....z from

    Is it possible to write any query or Stored Procedure or UDF like below. (-) is just a sample.

    Select b(-),e(-),f(-) from

    So it should display all columns expect b,e and f.

  • Not to my knowledge.

    Warm Regards,
    Neel aka Vijay.

  • You can with dynamic SQL. but the real question is WHY?


    N 56°04'39.16"
    E 12°55'05.25"

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply