SQL query for two column from and to with same value
Suppose you are developing a software, you have a database table with following structure:
zip_id from_zip1 from_zip2 ship_cost
1 0 100 40
2 101 200 50
3 201 350 100
In the data entry screen you put the Zip code as 315. Zip code 315 coming under zip id 3 and it's shipping cost is 100.
you want when user put zip 315 or any other zip then it's according shop cost automatically show.
So what will the sql query of this?
This will the query of that:
SELECT *FROM ship
WHERE (from_zip2>=315 AND from_zip1<=315)
ORDER BY from_zip2 DESC LIMIT 0, 1
Suppose you are developing a software, you have a database table with following structure:
zip_id from_zip1 from_zip2 ship_cost
1 0 100 40
2 101 200 50
3 201 350 100
In the data entry screen you put the Zip code as 315. Zip code 315 coming under zip id 3 and it's shipping cost is 100.
you want when user put zip 315 or any other zip then it's according shop cost automatically show.
So what will the sql query of this?
This will the query of that:
SELECT *FROM ship
WHERE (from_zip2>=315 AND from_zip1<=315)
ORDER BY from_zip2 DESC LIMIT 0, 1
0 comments:
Post a Comment