Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have a query that inserts using a select:

INSERT INTO courses (name, location, gid) 

SELECT name, location, gid 

FROM courses 

WHERE cid = $cid

Is it possible to only select "name,location" for the insert, and set gid to something else in the query?

1 Answer

0 votes
by (40.7k points)
edited by

Yes, it is possible to set gid to something else in the query and to select "name, location" for the insert, and. But, you need to check the syntax.

Are you interested in learning SQL from the basics! Refer to this video on SQL provided by Intellipaat:

Query:

INSERT INTO courses (name, location, gid)

SELECT name, location, 1

FROM   courses 

WHERE  cid = 2

You can add the constant of the same type as gid in its place, not just 1. You can make the cid value.

Related questions

Browse Categories

...