Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2007
    Posts
    3

    Unanswered: SELECT statement that excludes a field or two?

    Hi,

    While coding (PHP) especially with database transactions, I usually browse the content or check the the table structure directly from the 'terminal' or simply MySQL client. There are times that I want to view the records based on let's say 10 fields, but am interested only on 8 fields. So what command in SQL that explicitly exclude fields from a query or field list? In consequence, I will no longer type in 8 field names but instead a field name or two for exclusions. Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sorry, not possible

    you must list the columns you want
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    George
    Home | Blog

  4. #4
    Join Date
    Aug 2007
    Posts
    3
    Thanks for the replies and link!

  5. #5
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I agree entirely with the below (posted as a comment on said link):

    Frankly, the only time someone should be selecting * is for some adhoc data discovery; in which case, the inclusion of some extraneous columns shouldn't matter.

    Production level code should explicitly list the columns to be returned. The principal reason for this is to insure against schema changes. When a field is added to a table, select * will return it -- sometimes with unexpected results.

    With the myriad of IDEs available for database developers, including the entire list of columns should not be a burden
    However, i also noted another comment discussing views. If you really are continuously looking up data to check it, but want to omit your particular columns (large blob/text columns are a good example) then CREATE A VIEW with the specified columns you do want, then do SELECT * FROM <VIEW>
    Code:
    CREATE VIEW 'view_name' AS SELECT column1,column2,column3 FROM <table>;
    SELECT * FROM view_name;

  6. #6
    Join Date
    Aug 2007
    Posts
    3
    creating 'VIEW" is nice and I think the nearest alternative

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •