Current location: Hot Scripts Forums » Programming Languages » PHP » Another PHP/MySQL Question


Another PHP/MySQL Question

Reply
  #1 (permalink)  
Old 06-25-04, 12:55 PM
Lucas Lucas is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Mission, Texas
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Another PHP/MySQL Question

I want to select a row from two different tables, and I want the one row that is selected to have the latest time that was inserted into the database. So, like say row1 in table1 has a timestamp of 1050303 and row2 in table2 has a timestamp of 10505050. I only want row2, the one with the latest time stamp, to be selected. Is there anyway to do this in one query, and if not, can you show me how to do it anyway? Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-25-04, 01:27 PM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Best I can think of at the moment is:

PHP Code:

mysqlSELECT MAX(table1.timestamp), MAX(table2.timestampFROM table1table2;

+-----------------------+-----------------------+
MAX(table1.timestamp) | MAX(table2.timestamp) |
+-----------------------+-----------------------+
|        
20040626031407 |        20040626031424 |
+-----------------------+-----------------------+
1 row in set (0.00 sec
and then use PHP to compare the two values and output the greater value. But there *might* be a better way to do it with just SQL. Maybe someone can figure it out...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PHP] Array question UmiSal Script Requests 1 04-05-04 02:52 PM
Profession PHP/MySQL programming, Web site maintenance and web design offer procoding Job Offers & Assistance 0 04-01-04 01:35 PM
question and answer software jaydifox C/C++ 0 02-21-04 10:26 AM
Ask Question / Get Answer script. READ. Denin Script Requests 0 01-21-04 03:37 AM
I need a PHP/MySQL coder to help with my site. bhoard Job Offers & Assistance 8 07-07-03 11:25 PM


All times are GMT -5. The time now is 06:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.