Advertisement

05.23.2008 at 11:40AM PDT, ID: 23428557
[x]
Attachment Details

Select Next ID - Average

Asked by ncoo in MySQL, PHP Scripting Language, PHP and Databases

Tags: PHP, MySQL

I use both MySQL 4 and 5, so idealy the solution should work in both.

I have table_A which contains an primary index, value and average.

TABLE_A
ID|VALUE|AVERAGE

table_B links table_A to a category so that TABLE_A.ID=TABLE_B.AID

TABLE_B
AID|CID

I can create a list easily like so:

select * from TABLE_A
inner join TABLE_B on (TABLE_A.ID=TABLE_B.AID )
order by AVERAGE DESC

How do I get the next and previous ID when viewing just one ID?

I've done a query which displays just ID 20 with AVERAGE 3.44 but I want to know the next ID which has a AVERAGE higher then 3.44 and the previous ID which is lower.

select * from TABLE_A
inner join TABLE_B on (TABLE_A.ID=TABLE_B.AID )
where ID=20Start Free Trial
[+][-]05.23.2008 at 11:57AM PDT, ID: 21634791

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 11:59AM PDT, ID: 21634819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 12:12PM PDT, ID: 21634947

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 12:20PM PDT, ID: 21635023

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

Zones: MySQL, PHP Scripting Language, PHP and Databases
Tags: PHP, MySQL
Sign Up Now!
Solution Provided By: brad2575
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628