我想
insert into player table (col1,col2,col3)
values(data1,data2,select clubs.club_id
from club
where clubs.club_name='elahly' )
注意: data1,data2未定义或从任何表中复制其新值。
更新:
当我尝试在这些查询中插入我的值时:
INSERT INTO add_new_player (first_name, full_name,club_name,team,birthday,gender,weight,kata_kumite,individual_collective,
heavey_light,belt_color
,country,country_flags,date_of_admission)SELECT
'على','علا',
clubs.club_id,
'team.team_id',
'2000',
'ذكر',
'0',
'ابيض',
countries.country_id,'eg',
'2015-07-26 11:43:24'
FROM clubs inner join team on team.team_name='0' inner join countries on countries.country_name='قطر'
and clubs.club_name='elahly'
它给了我结果:
0 rows inserted. (Query took 0.0007 sec)
为什么没有插入行的问题。
答案 0 :(得分:1)
您需要使用INSERT INTO .. SELECT FROM
构建
insert into `player table` (col1,col2,col3)
SELECT data1, data2, club_id
from club
where club_name = 'elahly';
答案 1 :(得分:1)
尝试这样的事情:
INSERT INTO `your-table` (col1,col2,col3)
SELECT 'newvalue1','newvalue2', clubs.club_id
FROM club
WHERE clubs.club_name='elahly';
<强>更新强>:
格式化您的查询:
INSERT INTO add_new_player
(
first_name,
full_name,
club_name,
team,
birthday,
gender,
weight,
kata_kumite,
individual_collective,
heavey_light,
belt_color,
country,
country_flags,
date_of_admission
)
SELECT
'على',
'علا',
clubs.club_id,
'team.team_id',
'2000',
'ذكر',
'0',
'كاتا',
'جماعى',
'خفيف',
'ابيض',
countries.country_id,
'eg',
'2015-07-26 11:43:24'
FROM clubs
INNER JOIN team ON team.team_name='0'
INNER JOIN countries ON countries.country_name='قطر'
AND clubs.club_name='elahly'
确保您的SELECT查询返回行,并确保插入正确的数据类型。