views:

18

answers:

2

Hi, the following query

CREATE TABLE IF NOT EXISTS XY (
 x INT NOT NULL ,
 y FLOAT NULL ,
PRIMARY KEY(x)
)

INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y);

errors with

Error code 1064, SQL state 42000: 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 'INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y)' at line 7
Line 1, column 1

any ideas?

A: 

do you need the parentheses around the select statement

INSERT INTO XY (x,y)
select 1 as x ,(1/7) as y;
SQLMenace
i have tried with and without no difference in the error
Mark
+1  A: 

You should add ; after CREATE TABLE statement (or before INSERT statement) . You are trying to execute 2 different queries without separator.

CREATE TABLE IF NOT EXISTS XY (
x INT NOT NULL ,
y FLOAT NULL ,
PRIMARY KEY(x)
);  # !!! Originally, you missed ;

INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y);
a1ex07
this was an attempt at finding out why this query is not working,INSERT INTO resultprobability (ballNumber, probability)(select resultset.ballNumber ballNumber,(count(0)/(select count(0) from resultset)) probability from resultset group by resultset.ballNumber);
Mark