简体   繁体   English

我如何从另一个表中选择

[英]How do I do select into from another table

Basically I want to run a SQL statement like this, but I can't due to errors. 基本上,我想运行这样的SQL语句,但是由于错误而不能。 Not sure why? 不知道为什么吗?

INSERT INTO allevent (eventname) 
VALUES (select username from registered)

Msg 156, Level 15, State 1, Line 1 消息156,第15级,状态1,第1行
Incorrect syntax near the keyword 'select'. 关键字“ select”附近的语法不正确。

Msg 102, Level 15, State 1, Line 1 Msg 102,第15级,状态1,第1行
Incorrect syntax near ')'. ')'附近的语法不正确。

No need of parentheses around the SELECT statement in your query. 在查询中的SELECT语句周围不需要括号。

 INSERT INTO allevent (eventname) 
 SELECT username FROM registered

Parentheses with VALUES required, where some places like below: 括号内必须有VALUES ,如下所示:

INSERT INTO tablename (fieldname) 
VALUES ('field 01'), ('field 02');

Please find the syntax for the INSERT statement. 请找到INSERT语句的语法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一个表列中选择一个表? - How do I select a table from another table column? 如何根据另一个选择的结果制作一个SQL表? - How do I make a SQL table from the result of another select? 如何从另一个表中查找字段名的表中选择一个字段? - How do I select a field from a table where I am looking up the fieldname from another table? 如何选择另一个表中不存在的行 - How do I select rows which do not exists in another table 如何从另一个日期(来自 SQL 中的另一个表)中选择接下来的 6 个月日期? - How do I select the next 6 months date from another date ( which is from another table in SQL)? 如何从数据库中另一个表的SELECT查询中插入/更新表变量? - How do i INSERT/UPDATE a table varieble from a SELECT query from another table in the database? 如何在MySQL中使用SELECT语句从一个表中获取数据,并从另一表中覆盖数据? - How do I take data from one table, and overwrite it from another table, with a SELECT statement in MySQL? 如何通过select语句中的ID从另一个表中进行选择? - How do I select from another table by an id within a select statement? 如何在1个表中选择包含SQL中另一个表中的关键字的行? - How do I select rows in 1 table containing keywords from another table in SQL? 如何根据另一个表中的条件从一个表中创建 select 的存储过程 - How do I create a stored procedure that select from one table based on condition in another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM