Jump to content


Photo

Help with select syntax


  • Please log in to reply
3 replies to this topic

#1 acer88

acer88
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationNEw York

Posted 29 October 2006 - 11:07 PM

I get this error when trying to do a mysql query with select.

Here is the error I get:

SELECT Error: 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 'select barcode from itemdescription) order by listing.date DESC

and here is the code that I believe is generating the error:

//$records = mysql_query( "SELECT *  FROM listing where title like '%$title%' and barcode in (select barcode from itemdescription) order by date DESC")
$records = mysql_query( "SELECT listing.recordid,listing.barcode,listing.itemnumber,listing.title,listing.inputdate,itemdescription.category,
category.categoryname FROM listing left join itemdescription on listing.barcode=itemdescription.barcode left join
category on itemdescription.category=category.categoryid where listing.title like '%$title%'
  and listing.barcode in (select barcode from itemdescription) order by listing.date DESC")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($records);



what is wrong with my syntax?? Sometimes it just take another pair of eyes to spot the problem:) Thanks



#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 29 October 2006 - 11:26 PM

What MySQL version are you using? It looks like it's not happy with your subqueries, though there could be another syntax error there somewhere.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 acer88

acer88
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationNEw York

Posted 30 October 2006 - 12:13 AM

our hosting is through godaddy and they are using version 4.0.24

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 October 2006 - 05:01 PM

No subquery support until 4.1... though you could rewrite these as JOINs:

SELECT *  FROM listing INNER JOIN itemdescription USING barcode WHERE listing.title like '%$title%' ORDER BY listing.date DESC

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users