If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SELECT statement that excludes a field or two?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-07, 01:27
joboy joboy is offline
Registered User
 
Join Date: Aug 2007
Posts: 3
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.
Reply With Quote
  #2 (permalink)  
Old 08-08-07, 03:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
sorry, not possible

you must list the columns you want
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-08-07, 04:21
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 08-09-07, 22:31
joboy joboy is offline
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks for the replies and link!
Reply With Quote
  #5 (permalink)  
Old 08-10-07, 06:20
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I agree entirely with the below (posted as a comment on said link):

Quote:
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;
Reply With Quote
  #6 (permalink)  
Old 08-10-07, 22:54
joboy joboy is offline
Registered User
 
Join Date: Aug 2007
Posts: 3
creating 'VIEW" is nice and I think the nearest alternative
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On