如何在不使用子查询的情况下编写此查询?

时间:2019-11-24 17:57:42

标签: sql

INSERT INTO Reltab(id,tid) VALUES
      ((SELECT id FROM BlogDetails WHERE Title = '$title'),
      (SELECT tid FROM TagTable WHERE tname = '$words[$i]'));

1 个答案:

答案 0 :(得分:0)

您应该在此类查询中使用参数。然后,您可以使用join

INSERT INTO Reltab (id, tid)
    SELECT bd.id, tt.tid
    FROM BlogDetails bd JOIN
         TagTable tt
         ON bd.Title = ? AND tt.tname = ?;