I have table has
id,name,age,surname,lastname,catgory,active
instead of select name,age,surname,lastname,catgory from table
how can I make something like this select * from table but not select id,active
I have table has
id,name,age,surname,lastname,catgory,active
instead of select name,age,surname,lastname,catgory from table
how can I make something like this select * from table but not select id,active
The only way to do that that I know if is to enumerate each column you do want... no negative filters that I'm aware of.
select name, age, surname, lastname, category from table
you can't do that, sorry. Actually you shouln't have done it if you could - specifying these things explicitly is always better, assume other developer adds new field and your application will fail
I'm fairly certain you can't. Probably the best way I can think of is to create SELECT name, age, surname, lastname, category FROM table
as a view, then just SELECT * FROM view
. I prefer to always select from a view anyway.
However, as others have pointed out, if another column gets added to the view your application could fail. On some systems as well (PostgreSQL is a candidate) you cannot alter the table without first dropping the view so it becomes a bit cumbersome.
Is it really that big of a deal if your fetched array contains those two values? If you're not going to use them, it doesn't really matter if they're there or not. It doesn't seem very logical to keep adding additional code to not select something.
Unless there's some special extension in MySql you cannot do that. You either get all, or have to explicitly state what you want. It is best practice to always name columns, as this will not alter the query behaviour even if the underlying table changes.
but i can make it in a loop by foreach and use if key = id make contenue
There is no SQL syntax to support:
select * from table but not select id,active
If you want all but one or more columns, you have to explicitly define the list of columns you want.
You should not be using select * anyway. Enumerate the columns you want and only the columns you want, that is the best practice.
You are too advanced.
The only data language that I have seen that supports your syntax is the D language with its "...ALL BUT ..." construct:
[Wikipedia - D Language Specification][1]
There are some reference implementations available, but mostly for teaching purposes.
http://en.wikipedia.org/wiki/D_%28data_language_specification%29