1

Topic: Insertion in the table under a condition in mysql...

All greetings. Let we have some table
CREATE TABLE t1 (id INT, free_places INT, PRIMARY KEY (id));
And here it would be desirable for me to add in the second table
CREATE TABLE t2 (id INT, fname VARCHAR (30), lname VARCHAR (30), bday DATE...);
Values, BUT ONLY under a condition if value of a certain field free_places in t1 we tell> 30. Well here for example
If (SELECT free_places FROM t1 WHERE id = 1)> 30,
INSERT INTO t2 VALUES (...)
It would be quite good to throw still an error any with the text of an error otherwise.
Such generally it is possible to implement? I am simple something all rummaged around already. Googled already and separately INSERT INTO and INSERT INTO else if and so on.

2

Re: Insertion in the table under a condition in mysql...

Murderer wrote:

if (SELECT free_places FROM t1 WHERE id = 1)> 30,
INSERT INTO t2 VALUES (...)

INSERT INTO t2 (field1, field2...)
SELECT t1.field1/* value from a table field */
, ' some_value2 '/* value, as in VALUES */is simple
, ...
FROM t1
WHERE t1.id = 1
AND t1.free_places> 30

3

Re: Insertion in the table under a condition in mysql...

, yes, really plows)) And I and did not know that in SELECT it is possible to put the free value without a binding to any field. Thanks big)