Reputation: 4385
I have 2 tables -- one has ProductID
, [Product Name in English]
and Price
. The other table has ProductID
and [Product Name in Spanish]
.
I want a select query that gives me the Product Name in Spanish and Price.
How do I do this using MS SQL?
In terms of database design, might I as well just put everything in one table and make the select query simpler? ProductID
, NameEnglish
, NameSpanish
, Price
for example.
Upvotes: 1
Views: 6628
Reputation: 135799
SELECT t2.[Product Name in Spanish], t1.Price
FROM table1 t1 -- The English version
INNER JOIN table2 t2 -- The Spanish version
ON t1.ProductID = t2.ProductID
As for your design question, think about future expansion. Will you ever want to store the name in another language like French? You may ultimately want to introduce a table of languages and a cross-reference table linking product and language. Something like:
Upvotes: 6
Reputation: 39480
SELECT SP.ProductName, PRODUCT.Price from PRODUCT as PRODUCT
JOIN SPANISHPRODUCTS as SP ON PRODUCT.ProductID = SP.ProductID
Upvotes: 1
Reputation: 1891
You can do this with an inner join, but I don't see any reason to have two separate tables, I would combine them personally.
Upvotes: 1
Reputation: 17631
You could use the JOIN operator:
SELECT
tab2.[Product name in Spanish],
tab1.Price
FROM
table1 tab1
INNER JOIN
table2 tab2 on tab2.ProductID=tab1.ProductID
Upvotes: 1
Reputation: 1057
Combining them would be the best solution, but using a JOIN will solve your problem.
Upvotes: 1