Archive for the ‘mysql’ Category

mysql #1064

March 2, 2009 Leave a comment

Today evening I was as usual coding something and the code which I had written had ->
$q1="INSERT into table_name(name,time,desc) VALUES('$name','$time','$desc')";

The code just refused to do what it was supposed to. Yeah you might have figured that out.
Some learnings from this were – First thing you should do when things don’t work in mysql is echo the query and try running it in phpmyadmin or at the prompt!
I have been using mysql for like 1.1/2 years now and I come across this outlandish error. Almost eccentric and I tried looking at he code again and again to check if i misspelt something or missed a comma, whatever….Good that there weren’t any mistakes there, bad it took too much time. I slept for 2 hours very frustrated !! Then I went to phpmyadmin. and there I see the “ERROR” – #1064

At once googled and there I see the answer to my problems – reserved words.
Mysql has reserved words ! Some words cannot be used as identifiers directly and to use them all we need to do is quote them.
Query: INSERT into table_name(name,`time`) VALUES('abcd','23443545')
The identifier quote character is the backtick (“`”). TIME is a reserved word. Check out Schema object names

huh…another life’s problem solved!



December 29, 2008 Leave a comment

Today was the first time I came across the need for SELECT’s within SELECT in mysql. Actually never done much of non-trivial coding in mysql! Also i came up with the most-probable syntax of such a thing if it existed. Then I immediately asked a friend and he said it exists and very much the same syntax(kind of obvious) He said its called nested queries rather subqueries and then i discovered that the early need for such nested loops was to make the language more intuitive and less confusing and hence the name “Structured Query Language” (SQL). Just imagine if you have 10 tables and u have one single connector in two consecutive tables, and suppose you need information from tb10 using tb1 info; it would be a really bad way of coding by writing 10 separate queries and pipe the outputs at ecery single stage but instead use a lot more better way by writing just one query and go ahead..Smart and obvious!

Categories: mysql Tags:
%d bloggers like this: