# Really basic MySQL question.

**URL:** https://boards.straightdope.com/t/really-basic-mysql-question/98513
**Category:** Factual Questions
**Created:** [March 15, 2002, 8:35pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513 "2002-03-15T20:35:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![black\_rabbit](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@black\_rabbit](https://boards.straightdope.com/u/black_rabbit)
#### Post date: [March 15, 2002, 8:35pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/1 "2002-03-15T20:35:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![black\_rabbit](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@black\_rabbit](https://boards.straightdope.com/u/black_rabbit)
#### Post date: [March 15, 2002, 8:37pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/2 "2002-03-15T20:37:04Z")

</div>

**SELECT**.

Sigh…

---

<div class="post-metadata">

### Author: ![Enright3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/enright3/32/2897_2.png) [@Enright3](https://boards.straightdope.com/u/Enright3)
#### Post date: [March 15, 2002, 10:44pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/3 "2002-03-15T22:44:26Z")

</div>

> [@](#):
>
> \*Originally posted by black455 \*  
> \*\*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. \*\*

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

---

<div class="post-metadata">

### Author: ![black\_rabbit](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@black\_rabbit](https://boards.straightdope.com/u/black_rabbit)
#### Post date: [March 15, 2002, 10:57pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/4 "2002-03-15T22:57:33Z")

</div>

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**.

---

<div class="post-metadata">

### Author: ![Enright3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/enright3/32/2897_2.png) [@Enright3](https://boards.straightdope.com/u/Enright3)
#### Post date: [March 15, 2002, 11:35pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/5 "2002-03-15T23:35:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [March 16, 2002, 2:44am UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/6 "2002-03-16T02:44:00Z")

</div>

MySQL also supports basic regular expressions for wildcard searches: [http://www.mysql.com/doc/P/a/Pattern\_matching.html](http://www.mysql.com/doc/P/a/Pattern_matching.html)

---

<div class="post-metadata">

### Author: ![DMC](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dmc/32/18049_2.png) [@DMC](https://boards.straightdope.com/u/DMC)
#### Post date: [March 16, 2002, 1:18pm UTC](https://boards.straightdope.com/t/really-basic-mysql-question/98513/7 "2002-03-16T13:18:01Z")

</div>

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.
