在一个mysql查询中执行多个选择的更好方法?

时间:2016-02-08 02:37:04

标签: mysql

我有一个包含多个select语句的插入查询。我觉得这样做会更好(更高效,更优化等)。有什么建议?

   INSERT INTO log (logtype, subtype, src_ip, dst_ip, dst_port, query) VALUES (2, 1, 
    (SELECT src_ip FROM query WHERE uid="123"), 
    (SELECT dst_ip FROM query WHERE uid="123"), 
    (SELECT dst_port FROM query WHERE uid="123"), 
    (SELECT query FROM query WHERE uid="123"))

1 个答案:

答案 0 :(得分:4)

INSERT INTO log (logtype, subtype, src_ip, dst_ip, dst_port, query) 
SELECT 2, 1, src_ip, dst_ip, dst_port, query 
FROM query WHERE uid="123"