Vaibhav Deshmukh
Vaibhav Deshmukh

Reputation: 183

SQL Query related to joins?

Select * 
into relatesupply 
from
    OrderByStore m 
m.Product_Name,m.Quantity,n.Quantity 
inner join 
    presentsupply n on m.Product_Name = n.Product_Name 

I want relatesupply as a new table and join output will store at relatesupply ? How should I fire the query? Where OrderByStore and presentsupply are two tables

Upvotes: 0

Views: 78

Answers (4)

Tharif
Tharif

Reputation: 13971

Query will create a table relatesupply as you need with inner join OrderByStore and presentsupply :

SELECT        
    OrderByStore.Product_Name, OrderByStore.Quantity, 
    presentsupply.Product_Name AS Expr1, presentsupply.Quantity AS Expr2
INTO
    relatesupply
FROM            
    OrderByStore 
INNER JOIN
    presentsupply ON OrderByStore.Product_Name = presentsupply.Product_Name

enter image description here

Upvotes: 3

ApInvent
ApInvent

Reputation: 251

Try this:

select * 
into Relatesupply
from 
(
  select m.Product_Name,m.Quantity,n.Quantity 
  from OrderByStore m 
  inner join presentsupply n on m.Product_Name = n.Product_Name
) as X

Upvotes: 0

Tom
Tom

Reputation: 747

Create the table in advance (either manually or in script) and then insert the data using the insert statement. Avoid using the * to select columns, name them. Just a much neater way to do things in my opinion.

Upvotes: 1

Mukesh Kumar
Mukesh Kumar

Reputation: 985

insert into Relatesupply 
    select * 
    from OrderByStore m 
    join Presentsupply n on (Select * into  relatesupply  
                             from OrderByStore m  
                                  m.Product_Name,m.Quantity,n.Quantity  
                             inner join presentsupply n on m.Product_Name = n.Product_Name);

This query should work.

Upvotes: 0

Related Questions