Jump to content

Comparing 2 rows in mySQL?


woolyg

Recommended Posts

Hi all,

Just a non-urgent conversation piece more than anything: I'm looking around for some sort of app/utility that will take data from 2 rows in a MySQL table, and compare them, populating a visual or numeric report on the data.

 

Has anyone here ever used/seen/developed such an app? I'd be mighty interested in hearing from anyone that has.

 

Cheers all,

Woolyg

Link to comment
https://forums.phpfreaks.com/topic/49372-comparing-2-rows-in-mysql/
Share on other sites

That description is very general.. do you have something more specific in mind?  Are you looking at changes between two rows that differ over some axis (like time or location)?  Are graphs and tables the most common visual and numeric reports you want to generate?  And is it only ever 2 rows, or sometimes 3 or more?

It's only ever 2 rows (or 2 corresponding values in 2 rows) - I would like to basically use such a utility to show which row entry has the greater value.

 

 

Example table:

Row | Name | Age  | Salary

1.    | John  |  26  | 55000

2.    | Henry |  28  | 60000

 

 

- I'd like to specify it to show which Age and Salary is higher, or a graphical interpretation of the same (I'll be using it for rows that have up to 200 columns, so manually checking it won't be possible:) )

Finding a ready made script for something so specific will be difficult... so many variables - how do you define what two records should be compared?

 

Maybe there is something out there that will plot a graph for a single sorted field for all records in a table, even writing something that does the graphing may not be a difficult task but once, not only conditional comparisons but also conditional records is introduced, the result is a complicated script that is unlikely to exist.

It's only ever 2 rows (or 2 corresponding values in 2 rows) - I would like to basically use such a utility to show which row entry has the greater value.

 

 

Example table:

Row | Name | Age  | Salary

1.    | John  |  26  | 55000

2.    | Henry |  28  | 60000

 

 

- I'd like to specify it to show which Age and Salary is higher, or a graphical interpretation of the same (I'll be using it for rows that have up to 200 columns, so manually checking it won't be possible:) )

 

$sql = 'SELECT * FROM table ORDER BY Salary';
$result = mysql_query($sql) or die('ERROR! ' . mysql_error());

while($higher = mysql_fetch_assoc($result)) {
    echo $higher['Name'] . ' | ' . $higher['Age'] . ' | ' . $higher['Salary'];
}

 

Scribbling this off the top of my head, I doubt this will work, but it looks ok.

   

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.