I am new to SQL Server (coming from Oracle) and am having trouble getting a query to return the proper results...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
I have three tables:
FAMILY ======= family A123 A211 B343 LOCATION ======== epa_family location A123 Europe FAMILY_INFO =========== family mfg A123 us A211 themThe LOCATION table epa_family is a subset of FAMILY family. The FAMILY_INFO table family is also a subset of FAMILY family.
I am trying to get a list of all familes from FAMILY, all locations from LOCATION that have a corrosponding record in FAMILY; and the mfg field from FAMILY_INFO where there is a record returned for LOCATION. So for the above data the result set would be:
------------------------------ family location mfg ------------------------------ A123 Europe us A211 ? ? B343 ? ?I can get this to work in Oracle, but SQL Server either gives me syntax errors or incorrect results. I even tried the lazy man's method of building it using the Access query designer, but it didn't return the proper result set. Thanks for any help.
The first thing to watch for in going from Oracle to SQL Server is that you are using ANSI 92 syntax, especially when dealing with outer joins.
The query should look something like this:
Select a.family, b.location, c.mfg From family a inner join location b on a.family = b.epa_location Inner join family_info c on a.family = b.family
For More Information
- Dozens more answers to tough SQL Server questions from Michael Hotek are available here.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- The Best SQL Web Links
- Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL Server questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Microsoft SQL Server Installation
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.