• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

syntax problem i guess

don't work on mysql much but here goes:

I'm trying to
      insert into tbl
      (col1,col2)
      select 'hello','world'
      where not exists (select 1 from tbl where col1 = 'hello')

get an error
i know that on oracle (which i don't work on much either) one needs to select FROM DUAL
is there a requirement like that on mysql or ???

thanks
0
dgrafx
Asked:
dgrafx
  • 2
2 Solutions
 
Pratima PharandeCommented:
try this

  insert into tbl
      (col1,col2)
      select 'hello','world' from dual
      where not exists (select 1 from tbl where col1 = 'hello')
0
 
dgrafxAuthor Commented:
"DUAL is purely for the convenience of people who require that all SELECT statements should have FROM and possibly other clauses. MySQL may ignore the clauses. MySQL does not require FROM DUAL if no tables are referenced"
taken from dev.mysql.com

whats your opinion on this?
note that i cannot access that db right now or i would just try it - sorry.
0
 
Kevin CrossChief Technology OfficerCommented:
That is true when no WHERE clause is in place. My experience with 5.5 is with a WHERE clause you get an error without FROM DUAL.
0
 
dgrafxAuthor Commented:
thanks guys
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now