WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-07-2007, 03:55 AM
MOON MOON is offline
WebProWorld New Member
 

Join Date: Oct 2007
Posts: 8
MOON RepRank 0
Default Trouble getting latest record for a given item

I haven't found the information I seek in the manual yet, but I
continue to look. I am hoping that someone will give me a clue in the
mean time; hoping to shorten the time I need to fix this.

I tried the following:

SELECT *, max(price_date) FROM prices GROUP BY product_id WHERE
product_id = 1 AND price_date = max(price_date);

There is no knowing what the latest date is for a given item in the
DB.

But if I don't have the GROUP BY clause I get an error about misusing
max(), and using it, I still get an uninformative error about my WHERE
clause.

What I want ought to be obvious: the latest price for a given
product. How do I fix this SELECT statement to get what I want?

Thanks
_________________
Black Box Products Distributor How to trace a telephone number
Reply With Quote
  #2 (permalink)  
Old 11-07-2007, 08:00 AM
DaveSawers's Avatar
DaveSawers DaveSawers is offline
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 328
DaveSawers RepRank 1
Default Re: Trouble getting latest record for a given item

Why not change the select around (and simplify it) to something like:

select * from prices where product_id=1 order by price_date desc limit 1
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
MSN Item Search EliteAF MSN Search Discussion Forum 1 08-14-2007 02:02 PM
Single Item eComm Site ackerley1 eCommerce Discussion Forum 12 04-26-2007 11:30 PM
Interesting item I found on ebay countryjoe Breakroom (General: Any Topic) 0 11-10-2006 01:46 PM
Credit Card Processing for 1 item saylor eCommerce Discussion Forum 2 01-12-2006 05:49 AM
Link exchange with promotional item site 1234pens Marketing Strategies Discussion Forum 0 04-04-2004 02:41 PM


Search Engine Friendly URLs by vBSEO 3.0.0