Search code examples
mysqlstatements

MySQL Statements


I have been google-ing for the answer already, but can't really find good info. Its been a while I've played with SQL statements, but now i need it again.

Quick question: Is it possible to use the count statement in a insert statement? What i want to see is the following. Can't remember if this is possible, or its better with and IF/ELSE statement in between.

INSERT INTO tbltable (Row)
WHEN (SELECT COUNT(*) FROM tbltable WHERE Row = "Hello" > 1)
VALUE "Value1";

Thanks in advance!


Solution

  • You can do it like this:

    INSERT INTO tbltable (ROW)
    SELECT DISTINCT "Value1"
    FROM tbltable
    WHERE ROW = "Hello"
    HAVING COUNT(*) > 1