Question: SQL combine WHERE and ORDER BY in one statement

Question

SQL combine WHERE and ORDER BY in one statement

Answers 0
Added at 2017-02-23 21:02
Tags
Question

I have a problem with my database request(I use Sinatra for Ruby). There's a database where I store some articles with their attributes like the price and so on.

When I request the articles everything is fine. It also include the search term in a WHERE clause. But when I want to use ORDER BY preis in addition to the statement there's an error. But when I remove the WHERE condition it works ?!

Here are my statements that are working:

"SELECT * FROM artikel ORDER BY preis; "

"SELECT * FROM artikel WHERE name LIKE '%#{@suchbegriff}%';"

And this statement is not working:

"SELECT * FROM artikel WHERE name LIKE '%#{@suchbegriff}%' ORDER BY preis;"
Answers to

SQL combine WHERE and ORDER BY in one statement

Source Show
◀ Wstecz