选择还是插入表格?

时间:2012-11-02 21:20:12

标签: mysql

  

可能重复:
  How to 'insert if not exists' in MySQL?

我想做一个select语句,但如果没有匹配的行,那么我想插入一行并获取行id。我不确定如何撰写声明。我想出了这个,但我不确定它是否有效,但是如果它确实有更简单的方法来写它?

insert into Blah(a,b,c) select aval, bval, cval 
where null = (
    select id from tbl where cond=1
);
select id from tbl where cond=1;

0 个答案:

没有答案
相关问题