?
Solved

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

Posted on 2008-10-24
4
Medium Priority
?
1,023 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
jamesgu earned 1400 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 600 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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