Dan wrote: > > Hi there, quick and annoying SQL problem, was debating about whether to post > it here or DBI, I figured DBI was for DBI related issues, and this is just a > plain SQL problem. Excuse me if I'm wrong though, but thought I'd ask > anyway. > > I have an SQL statement as follows, > > SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC > > which fails giving an error on the to=1 part. > > I've tried doing that statement without the 'to=1 AND' part, and it works > fine returning all and more of the data that I want. However when i ask it > to be more specific, it fails. I've also tried > > SELECT * FROM memodata WHERE to=1 > > which also fails on the to=1 part. I've also tried putting in other column > names, like from=1, but that fails too. And I'm totally clueless as to why, > as the syntax follows the manual on mysql.com exactly. > > Any pointers as to where I'm going wrong?
It would be nice to know what error your getting, but the reason is certainly that both 'to' and 'from' are reserved words in MySQL. Take a look here http://www.mysql.com/doc/en/Legal_names.html Quote your column names with backticks: SELECT * FROM memodata WHERE `to` = 1 AND `readdate` = `sent` ORDER BY `id` ASC and it should work for you. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>