Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Creating and Managing Databases with phpMyAdmin in cPanel.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

16 Experts available now in Live!

Get 1:1 Help Now