Click to See Complete Forum and Search --> : SQL fetch the column smaller than column?


kennyTE
07-19-2007, 07:39 PM
i have a table looks like this (sales_man_id)
---------------------
(id)(sales_man_id)(set_target_sales)(achieve_sales)
1 5004 1000 5
2 5005 1000 8
3 5006 1000 2
4 5007 1000 2
5 5008 500 2
6 5009 500 1

---------------------

i want to find out only 5 salesman where achieve_sales is not hit base on the set_target_sales and achieve_sales where is smallest. So that i can call 5 selected salesman to do the new sales for tomorrow.

my sql queries looks like this:
---------------------
SELECT sales_man_id FROM
sales_person
WHERE set_target_sales > achieve_sales
ORDER BY achieve_sales
LIMIT 5
----------------------

it return from the query as:

sales_man_id
5008
5009

what happen, and how? suppose i want the query return :

sales_man_id
5009
5008
5007
5006
5004

what i do wrong with my sql, can some one teach me how?

mattyblah
07-20-2007, 11:38 AM
are you sure thats the exact query thats getting run? I have a hard time believing that, because you should be returning more rows and also the data is ordered wrong. The results should be how you listed, as long as you qualify the order by with the sales_man_id desc also.

kennyTE
07-21-2007, 09:23 PM
Sorry,
My data type is varchar, i change to int, that work for me right now. Thanks.