hi all ,
i have two tables , first one for companies , and second one for companies offers :
companies table design is :
[table=“width: 500”]
[tr]
[td]company name[/td]
[td]company type[/td]
[/tr]
[/table]
offers table
[table=“width: 500”]
[tr]
[td]id[/td]
[td]company_name[/td]
[td]offer_name[/td]
[td]speed[/td]
[td]price[/td]
[td]cap_limit[/td]
[td]offer_date[/td]
[/tr]
[/table]
how it will be the query to sort , min price and max speed , or max cap_limit and min price …i want the user will sort offer depend on multi criteria
i hope u got me , thanks a lot guys
First of all, I’d add a company id column to the companies table, and use that id as the foreign key in the offers table.
About your question, you can sort on multiple fields, but of course it will sort on one field, and then within each value of that first field, it will sort on the second field, ecc.
So what exactly do you mean when you say “to sort min price and max speed”? Can you give a data example?
i have list of companies , and i want to sort companies who have cheapest price , and highest speed and so on
Sorry, I didn’t understand your query…
[table=“width: 500, class: outer_border”]i dont know why u guys dont understand maybe i did not explain very well …
[tr]
[td]company_name[/td]
[td]type[/td]
[/tr]
[tr]
[td]x[/td]
[td]3g[/td]
[/tr]
[tr]
[td]y[/td]
[td]wimax[/td]
[/tr]
[/table]
[table=“width: 500, class: outer_border”]
[tr]
[td]id[/td]
[td]company_name[/td]
[td]offer_name[/td]
[td]speed[/td]
[td]cap_limit[/td]
[td]price[/td]
[td]offer_date[/td]
[/tr]
[tr]
[td]1[/td]
[td]x[/td]
[td]xx1[/td]
[td]6M[/td]
[td]100GB[/td]
[td]10.00[/td]
[td]date[/td]
[/tr]
[tr]
[td]2[/td]
[td]x[/td]
[td]xx2[/td]
[td]5M[/td]
[td]90GB[/td]
[td]9.00[/td]
[td]date[/td]
[/tr]
[tr]
[td]3[/td]
[td]x[/td]
[td]xx3[/td]
[td]5M[/td]
[td]80GB[/td]
[td]8.00[/td]
[td]date[/td]
[/tr]
[tr]
[td]3[/td]
[td]y[/td]
[td]yy1[/td]
[td]6M[/td]
[td]90GB[/td]
[td]11.00[/td]
[td]date[/td]
[/tr]
…
[/table]
if i want to sort by minimum price then hieghest speed for each company
it will be:
3 x xx3 8.00 5M 90GB
2 x xx2 9.00 5M 80GB
…
It looks like all you need is an ORDER BY clause. Please take a look at the manual: http://dev.mysql.com/doc/refman/5.5/en/select.html
can i say … order by price ASC , speed Desc … ?
r937
August 25, 2012, 12:15am
8
yes, you can say that
but i think you oughta test it first, so you know how it works