Really basic MySQL question.

I’m trying to do a simple query filtered via a where clause, eg:

SELCT * FROM table_name WHERE column_name = key_value

I keep getting an error telling me that key_value is an invalid column. What gives?

I tried googling for this, but all I got was actual error pages from various sites, and the various developer’s sites aren’t much help for really basic questions.

Any help is appreciated.

SELECT.

Sigh…

I don’t know about MySql, but this is a common error if you use double quotes when you need single quotes.
(I’m assuming you made a typo on the word “SELECT”)
For example:
SELECT *
FROM EnrightsTable
WHERE LastName = Enright3 is incorrect. It should read:
SELECT *
FROM EnrightsTable
WHERE LastName = 'Enright3

Hope this helps.

E3

I didn’t even realize I was supposed to use quotes around the key at all at all, and I’ll be damned, it works. Thanks, Enright3.

To do wild card searching (unless you’re using an access database) you can replace the =‘searchdata’ with LIKE 'searchdat%'

So to search for all values in the specified column for any data that starts with ‘enri’ you would put:
SELECT *
FROM table
WHERE LastName LIKE ‘enri%’

E3

MySQL also supports basic regular expressions for wildcard searches: http://www.mysql.com/doc/P/a/Pattern_matching.html

An additional note, in case you were wondering why the parser had a problem with a key_value being an invalid column. Without the quotes, the parser assumes the search string is a column, and that you are trying to compare the two columns. Since there is no column with that name, it gives the error.

If that didn’t make sense, using a search string of Smith as an example and a column named LastName, the parser thinks you want all records where the LastName column and the Smith column have the same data.