I am working on a table in which I have 2 records with same job order ID's but different quantities and reference ID's in the respective fields. I have written the following query :
"SELECT MIN(quantity) AS 'q'
FROM ready_for_delivery
WHERE joborderid = trim($_GET['id'])";
For example :
If I am having 2 records with job order id=45, where reference id for 1st record is 8,quantity is 800 and reference id for 2nd record is 9, quantity is 450. With the above query the 2nd record's quantity should be selected. But neither is selected.
Please guide me. Thanks.
SELECT quantity as 'q' FROM ready_for_delivery WHERE joborderid = '".$_GET['id']."' ORDER BY quantity ASC LIMIT 1
You really should use prepared statements there, to prevent SQL injections.
there is a problem with your GET variable and SQL. first, you have an extra "
and the second it is better to use a variable in your query or at least something like '{$_GET['id']}'