Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select * from mytable where <ANY FIELD> = something

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
Is it possible to write a select statement that will check the all the fields for an equality without having to name all the fields.

the statement would be something like
select * from MYTABLE where * = "thing to compare"

obvously this doesn't work. but is there a way to do what I'm getting at?
 
No. SQL requires that you explicitely name the columns used in a WHERE clause.

The only place the "*" has any meaning is in the specification of rows to return. ______________________________________________________________________
TANSTAAFL!
 
Why don't you use..

SELECT * FROM MYTABLE
WHERE name = "whatever"
OR lastname= "whatever"
OR username="whatever"

I realize this is laborious if you have a lot of fields and you need to check all of them, but I think it's the only way to do what you want..

 
yeah,
actually i was looking to be able to do it ease my command line life. i am often looking at tables right from the mysql command line. and there are times when i just want to know if a certian value is in the table, i don't care where, just if it is in there. thus, i have to describe the table, get all the fields, then search. it can be a pain, and i was looking to simplify my life.

thanks anyway
 
One way to ease your life when writing SQL is to put it in a file instead of typing it in at the command line.
You can access the file with the \. command.

This way, if you use one type of SQL statement often, you can just modify an existing query instead of retyping the whole thing every time.

It also eases the pain of typos half way through a query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top