General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 11th, 2004, 09:41 AM
gharryh gharryh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 gharryh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Problems with SELECT MAX()

Can anyone tel why the statement
MYSQL_QUERY("SELECT MAX(dateUpdate) AS dateUpdate FROM organisatie")
does not produce the same result as
MYSQL_QUERY("SELECT * FROM organisatie WHERE dateUpdate = (SELECT MAX(dateUpdate) FROM organisatie)")

The first one gives met the correct last dateUpdate but i want to get not just the date from that record but all the information i contains. What am i doing wrong.

Harry

Reply With Quote
  #2  
Old April 22nd, 2004, 01:01 PM
DevZen DevZen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 DevZen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

Harry,

Your first query will give you the MAX date over all the records you have on your table.

MYSQL_QUERY("SELECT MAX(dateUpdate) AS dateUpdate FROM organisatie")

Your second query is giving you any number of results that match the highest date.

MYSQL_QUERY("SELECT * FROM organisatie WHERE dateUpdate = (SELECT MAX(dateUpdate) FROM organisatie)")

So if your max date is April 20 and you have several records that have this date, you will get them and the results will be different.

The question is, what exactly do you want?

Note: You are missing the field name you need for your function:

MYSQL_QUERY("SELECT * FROM organisatie WHERE dateUpdate = (SELECT MAX(dateUpdate) AS dateUpdate FROM organisatie)")

I'm not sure if that's what you are looking for either...

Gil

Reply With Quote
  #3  
Old April 22nd, 2004, 08:46 PM
odon odon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 odon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
find max

$q_pns = "select max(tmt_golongan) maks from riwayat_golongan1 group by nip order by nip";

$h_pns = mysql_query($q_pns);
$pns = mysql_fetch_array($h_pns);
$temp = $pns[maks];

$all_pns = "g1.tmt_golongan in ('$temp') and";

i have problem with the program above.
i want the $temp contains all the "maks" value, since the $all_pns only contains some maks value but i have no idea what to do.

actually i can solve the problem using select ...where tmt_golongan=(select...), but mysql doesn support the function, and i'm not going to use the newest mysql at this moment.

thx n sorry for my english

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Problems with SELECT MAX()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway