向一行php添加两个插入查询

时间:2017-04-22 15:55:52

标签: php mysql

是否可以添加插入查询到一行?当我将查询作为两个运行时,它们都会添加到不同的行中。

$query1  = "INSERT INTO `mysaved` (`Username`) VALUES ('bob123')";
$query2 = "INSERT INTO `mysaved` (`Name`, `Image`) 
SELECT * 
FROM sport b
JOIN sport a
on a.Tag = b.Name
where a.SportID <> b.sportID and a.Name = 'Football'"

1 个答案:

答案 0 :(得分:2)

您可以将值放入select

INSERT INTO mysaved (Name, Image, Username)
SELECT name, image, 'bob123'
FROM sport b
JOIN sport a
on a.Tag = b.Name
where a.SportID <> b.sportID
and a.Name = 'Football'