Solved

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

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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 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