DotDragnet
May 23, 2012, 04:14:01 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: SQL Query  (Read 617 times)
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« on: January 13, 2010, 06:14:30 PM »

Anyone see anything wrong with this?

$top_info_query = tep_db_query("select max(products_id) as max_id FROM " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$cPath . "' and p.products_status = '1'");

Trying to get the max "product id" on a per category basis.

Error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' categories c where p.products_id = p2c.products_id and p2c.categories_id = c.ca' at line 1

I've become fuddled.  Thanks all.
 
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #1 on: January 13, 2010, 10:10:05 PM »

You don't want a left join, replace that with a comma.

Also max(p.products_id)
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #2 on: January 13, 2010, 11:55:38 PM »

Thank you very much Jason!
Works perfectly now.  TYVM
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!