PDA

View Full Version : Select everything BUT this


Ultragames
02-07-2006, 10:03 PM
I want to select everything from one table, and everything from another, except one field.

Theoreticly, it would look like this

SELECT eTime.*, eTime_Ex.*, !eTime_Ex.time_id FROM . . . . . .

How can this be done? The problem is that eTime and eTime_Ex share a field, (used in a LEFT JOIN.) However the id in the second table may sometimes be null, which screws up my PHP arrays because they have the same key, but different values.

I know i could just do eTime.*, and then list every field from eTime_Ex except the id, but thats ugly and long.

Any ideas?

Kid Charming
02-07-2006, 10:16 PM
I know i could just do eTime.*, and then list every field from eTime_Ex except the id, but thats ugly and long.



That's how you have to (and how you should) do it. Using the wildcard is convenient, but not necessarily efficient or good practice. First, if you're not actually using every column in your table, selecting them all with the wildcard is wasteful. Second, it's kind to the next person who has to work on your code to know what fields a query is working with.

Either way, though, the only way to not select a field is to not have it in your SELECT list. You can't negate something selected with the wildcard.

Ultragames
02-07-2006, 10:23 PM
I am using all fields but one, and i didn't feel like have all 15 listed there. It wastes space.

felgall
02-08-2006, 09:00 PM
If you don't want to retrieve all of the fields then you need to list the ones you want.

Your waist has nothing to do with computers.

raf
02-08-2006, 09:16 PM
I am using all fields but one, and i didn't feel like have all 15 listed there. It wastes space.
even if you would be using all fields, then it's still better to specify all fields in your fieldlist.
imagine you add a new column to that table, then it will automatically be included in your resultset, without you using it...