Question:
I'm having a SQL syntax error pop up despite various changes to the query, help?
Vipaka
2011-10-17 18:50:38 UTC
I'm trying to find duplicate values in my SQL table so I can use them, but keep getting syntax error messages. What's wrong with it?

$sql = "SELECT item_link
COUNT(*)
FROM " . ITEMS_TABLE . "
GROUP BY item_link
HAVING (count(*) > 1)";
$result = $db->sql_query($sql);
Three answers:
Myke
2011-10-17 19:03:31 UTC
I didn't build and run this to verify, but I see two possible issues. 1) I think you need a comma between item_link and COUNT(*) after SELECT... SELECT item_link, COUNT(*)... because you are selecting two (2) values. Also, issue 2) You may need to put your results into a list instead of a scalar - again, because you are selecting two columns instead of only a single column. So, results may have to be @result (but, I'm not sure what sql_query() returns... does it return a list, or a scalar value?
MT
2011-10-17 18:57:43 UTC
Probably the missing comma after item_link?



$sql = "SELECT item_link, <--- this one?

COUNT(*)

FROM " . ITEMS_TABLE . "

GROUP BY item_link

HAVING (count(*) > 1)";
romine
2016-12-07 16:50:18 UTC
please for the affection of jezus christ dont a million) create tables on your mainscript 2) feed sq. queries to the customers, thats begging to get hacked sooner or later (google: sq. injection) this doesnt answer your question, i comprehend, yet please save it in ideas. additionally: examine if the PK is placed properly, perhaps it could be close to its namesake


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...