1

I've currently got an SQL table, with duplicate entries. Some entries have more information than others, and I would like to get the entry with the most information. This is my code, which fails, and I'm not sure is appropriate to suit my needs.

"SELECT * FROM People WHERE Name='%s'
 AND (Surname IS NOT NULL OR Surname IS NULL)
 AND (Year_Born IS NOT NULL OR Year_Born IS NULL)
 AND (Height IS NOT NULL OR Height IS NULL)
 AND (Hair_Color IS NOT NULL OR Hair_Color IS NULL)
 AND (Eye_Color IS NOT NULL OR Eye_Color IS NULL" % (name[0].get_child().get_text())

name[0].get_child().get_text() -> contains the name of the person I would like to look up.

The only message I get, is the following one: "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 '' at line 1"

Frankie
  • 48
  • 2
  • 7
  • And how is your code failing, exactly? An exception with traceback, 0 results? – Martijn Pieters Jan 14 '14 at 18:42
  • In the traceback, I do not get much information. The only message is this: "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 '' at line 1" – Frankie Jan 14 '14 at 18:44
  • Update your question with this info. – sachleen Jan 14 '14 at 18:44
  • Now that it's formatted better, Your query is failing because you're missing a close paren at the end. That being said, checking for something OR not something evaluates to 1 in logic. – sachleen Jan 14 '14 at 18:45
  • Indeed, you're right, Thank you so much! – Frankie Jan 14 '14 at 18:47

1 Answers1

0

Your query fails because you are missing a close paren at the end:

 AND (Eye_Color IS NOT NULL OR Eye_Color IS NULL" %
 AND (Eye_Color IS NOT NULL OR Eye_Color IS NULL)" %
                                                ^

As for your actual problem, see these questions:

Community
  • 1
  • 1
sachleen
  • 30,730
  • 8
  • 78
  • 73