Solved

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

Posted on 2008-10-24
4
1,014 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now