Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this query be simplified? Version 3.23.55

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
I have 2 tables that I am trying to compare prices with:

table2000
-->id
-->item
-->price

table2003
-->id
-->item
-->price

I want to see what differences there are with the 2 tables. I would like to step through the records in 'table2000' and for each 'item', find a similar 'item' in 'table2003'. Is there a simpler way than the PHP code shown below to run the MySQL query? Could this be handled in a single SQL statement on a 3.23.55 MySQL server?

print (&quot;ITEM - 2000 Price :: 2003 Price<br>&quot;);

$Query=&quot;SELECT * FROM table2000&quot;;
$Result=mysql_db_query (mydatabase, $Query, mysql_connect (localhost,root,''));
while ($Row=mysql_fetch_array ($Result)){


$SubQuery=&quot;SELECT * FROM table2003 WHERE table2003.item=$Row[item]&quot;;
$SubResult=mysql_db_query (mydatabase, $SubQuery, mysql_connect (localhost,root,''));
while ($SubRow=mysql_fetch_array ($SubResult)){

print (&quot;$Row[item] - $Row[price] :: $SubRow[price]<br>&quot;);

}

}

- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
eeek- I should have realized this earlier.

I seriously simplified the example to make it explainable in this forum. I should have simplified it for myself as well. There are several more checks that I need to perform on other columns in the table that were throwing me off the basic task.

Thanks for the slap on the back of the head.

My mind is getting fuzzy from sifting through so much useless data.

- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
jimoblak:
Don't worry about it -- we all have brain cramps from time to time.

I had started wondering, though, if your post was a trick question or something. I've seen you answer much trickier questions than this one.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top