How can I check two conditions before inserting?

后端 未结 3 1336
忘掉有多难
忘掉有多难 2020-12-30 17:57

I have three tables:

// Posts
+----+----------+---------------+-----------+
| id |  title   |    content    | id_author |
+----+----------+---------------+--         


        
3条回答
  •  执念已碎
    2020-12-30 18:43

    INSERT INTO Votes (id_post,id_user)
    SELECT p.id, u.id
    FROM Posts p
        INNER JOIN Users u ON 1 = 1
    WHERE p.id_user = :author
        AND u.id = :current_user_id
        AND u.active = 1
    LIMIT 1;
    

提交回复
热议问题