Advertisement

08.29.2008 at 10:33AM PDT, ID: 23689543
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

query for record with minimun value at column

Asked by ioustinos_sarris in PHP and Databases

Hi there. I have a table of items which have id,name and weight.

Given the id of one item i want to retrieve the id and name of the item with the next highter weight value.
For example if item with id 345 has weight 10 i want the id and the name of the item with weight higher than 10 but closest to 10.

So far i am doing this but sure there is a better way with less queries.
1. get the weight for the given id
SELECT weight FROM items where id = $item_id
i keep the result in a variable $this_weight

2. get the next weight
SELECT MIN(weight) as next FROM items where weight < $this_weight
i keep the result in a variable $next_weight

3 get the id and name of the wanted item
SELECT id,name FROM items WHERE weight = $new_weight

I am pretty sure 2 and 3 can be combined into one query using group by but i am not sure how
Any help would be appreciated.Start Free Trial
[+][-]08.29.2008 at 10:45AM PDT, ID: 22347626

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Sign Up Now!
Solution Provided By: JMT116
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628