Click here to Skip to main content
14,430,403 members
Rate this:
Please Sign up or sign in to vote.
To tell you in advance, this is all for homework so it's just basic.
But, I'm having problem with writing one specific query.
I have a table with, let's say: typeColumn and this typeColumn has two values 'dog' and 'cat'.
What I want is to get only the rows with 'dog' value.

What I have tried:

adapter = new MySqlDataAdapter("SELECT * FROM `ads` WHERE `typeColumn` = `dog`", connection);

I keep getting the 'dog' value doesn't exist.
Updated 13-Sep-19 8:58am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

How to write correct SQL query?

Obviously, you are very new to SQL, you need to study SQL more.
Here is a nice tutorial site: SQL Tutorial[^]
Look at your query:
SELECT * FROM `ads` WHERE `typeColumn` = `dog`

you use quotes 3 times, the first is a table name, second is a column name and third is a literal string.
Just like with any computer language, anything matters, the quote is the string delimiter and must be used for nothing else.
Look at this page, there is examples of select: SQL SELECT Statement[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100