简体   繁体   中英

SQL Queries - Insert Statement with Select (only using one column of select)

So, I'm writing a query to insert a record into a table which needs to select part of the inserting data from another database. The following is what I have so far:

INSERT INTO
    teams_views (teamId, viewerId)
VALUES (
    (SELECT teamId FROM teams WHERE teamName = 'name'),
     1
);

I have searched about and have found loads of insert selection answers, but I haven't been able to find any queries for a single column selection. What can I do with my query to make this possible?

Thanks!

http://sqlfiddle.com/#!9/e2a75/2

INSERT INTO
    teams_views (teamId, viewerId)
SELECT teamId,1
FROM teams 
WHERE teamName = 'name';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM