select all columns except one?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

select all columns except one?

Post by mudkicker »

i have a table with 17 columns i want 16 columns to select. is there another way to write it than SELECT [all tablenames that i want] .... query?

thanks,
have a nice day
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

if you want to "not-select" the last one, this would work:

"SELECT * FROM 'your_table' ORDER BY 'some_column' ASC LIMIT 16"

-Nay
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Nay, you seem to be confused between ROWS and COLUMNS!

Mudkicker, unless the 1 field you don't want is a large field like a blob or long text you might as well just pull all of the fields.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Wayne wrote:Nay, you seem to be confused between ROWS and COLUMNS!

Mudkicker, unless the 1 field you don't want is a large field like a blob or long text you might as well just pull all of the fields.
no it's the id column max. 3digits long :)
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

then just use star. yeah it seems like a waste since that's how you're searching, but it's actually the easiest thing to do
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Select * is the easiest thing to do, but I would certainly resist the temptation. Bite the bullet and code all 16 columns in the select statement.
By doing so, you have also documented the portion of the table structure of interest to this script. 6 months, a year from now when you have to update the script, you will be glad you did! Also format your sql in a readable manner:

Select colA
, colB
, colC
, colD
FROM Table A
WHERE colB = $somevalue
AND colC = $anothervalue
ORDER BY colB, colC

A little extra work upfront, but anything you can do to make your script more readable and easy to understand will profit you immensely in the future.

fv
Post Reply