Solved

Proper SQL syntax for a MySQL insert query with inner join?

Posted on 2008-10-24
4
1,017 Views
Last Modified: 2012-06-27
What would be the proper way to write a query like this?

insert into productcategory(Fkproductid,fkcategoryid)
   ((select DISTINCT pg.fkproductid from productgroupdetail pg
      INNER JOIN temp t ON pg.sku = t.sku),64)

I'm basically attempting to insert the fkproductid of all sku's in temp table + the fkcategoryid of 64 into the product table.

table structure:

productcategory has 2 fields, both int(10): fkproductid, fkcategoryid

temp has 1 field, sku(varchar(20)

productgroupdetail has sku(varchar(20)), fkproductid(int(10))


Thanks!

0
Comment
Question by:jmoriarty
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
jamesgu earned 350 total points
ID: 22801393
insert into productcategory(Fkproductid,fkcategoryid)
   (select DISTINCT pg.fkproductid,64 from productgroupdetail pg
      INNER JOIN temp t ON pg.sku = t.sku)

0
 
LVL 22

Assisted Solution

by:dportas
dportas earned 150 total points
ID: 22802141
INSERT INTO productcategory (Fkproductid,fkcategoryid)
   SELECT DISTINCT pg.fkproductid,64
   FROM productgroupdetail pg
   INNER JOIN temp t
    ON pg.sku = t.sku;
0
 

Author Comment

by:jmoriarty
ID: 22805480
Ah, now I see; the SQL syntax comes after the values.

So the typical structure would be:

INSERT INTO tablename (fields)
value1, value2, etc
followed by join syntax and/or where clauses, etc.
0
 

Author Closing Comment

by:jmoriarty
ID: 31509879
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Creating and Managing Databases with phpMyAdmin in cPanel.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question