Reputation: 138
Hello this is driving me crazy. I can't get this query to work with the WHERE clause. It works without it. I have tried everything. I have looked at dozens of websites and dozens of questions here. I can't see anything wrong with this query. But it gives me this error whenever I try to use a WHERE clause:
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `cond` = '1'' at line 4
I have tried it with spaces and without, with single quotes and without, I have tried mysqli. I just can't figure out what the problem is.
Here is the code I currently have:
$sql = <<<SQL
SELECT *
FROM `master_inv`
ORDER BY `sku`
WHERE `cond` = '1'
SQL;
Upvotes: 0
Views: 238
Reputation: 122
It is just the order which is incorrect try:
SELECT *
FROM `master_inv`
WHERE `cond` = '1'
ORDER BY `sku`
Upvotes: 0
Reputation: 101
Your SQL statement is out of order and your missing a select statement.
The ORDER BY statement should be placed after the WHERE clause
SELECT *
FROM master_inv
WHERE cond = '1'
ORDER BY sku
Upvotes: 0
Reputation: 1819
WHERE clause goes before ORDER BY.
$sql = <<<SQL
SELECT *
FROM `master_inv`
WHERE `cond` = '1'
ORDER BY `sku`
SQL;
Upvotes: 8