Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to create an inner join

Posted on 2008-10-13
3
Medium Priority
?
1,333 Views
Last Modified: 2012-05-05
I am using Microsoft Query to query two table and return the data into Excel.  I went to w3school.com to learn how to create an inner join.  When I followed the instructions I received a syntax error.  When I used MS Query's visual editor it generated the code I have in the code snippet box.  Listed below are my two tables.

CGEQUP_All
    InventoryStatus
    StockNo

CGNOTE
    Note
    NoteSegNo
    StockNo


This is the example that w3schools gives:
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Does this syntax not work with MS Query or Excel?  It seems to be using a where statement instead of inner join.

select CGEQUP_All.StockNo,
       CGNOTE.Note
from   JDIS_Data_files.CGEQUP_All CGEQUP_All,
       JDIS_Data_files.CGNOTE CGNOTE
where  CGNOTE.StockNo = CGEQUP_All.StockNo
   and
       (
              (
                     CGEQUP_All.InventoryStatus='H'
              )
          and
              (
                     CGNOTE.NoteSeqNo>0
              )
           or
              (
                     CGEQUP_All.InventoryStatus='R'
              )
          and
              (
                     CGNOTE.NoteSeqNo>0
              )
           or
              (
                     CGEQUP_All.InventoryStatus='I'
              )
          and
              (
                     CGNOTE.NoteSeqNo>0
              )
       )

Open in new window

0
Comment
Question by:Majikthise
3 Comments
 
LVL 5

Accepted Solution

by:
PaulKeating earned 500 total points
ID: 22707773
INNER JOIN is SQL-92 and is still not implemented in certain dialects of SQL. Besides which, in simple cases it's wordier than the old way, which is of course still legal. Recipe for translating a 2-table inner join into SQL-86:
1. replace INNER JOIN with a comma
2. replace ON with WHERE

So

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

can also be rendered

SELECT column_name(s)
FROM table_name1, table_name 2
WHERE table_name1.column_name=table_name2.column_name


0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 22707779
The first condition in the where clause essentially inner joins the tables on StockNo but different applications handle SQL differently.  In T-SQL, I would write it like this:
SELECT CGEQUP_All.StockNo, CGNOTE.Note
FROM JDIS_Data_files.CGEQUP_All
INNER JOIN JDIS_Data_files.CGNOTE
ON CGNOTE.StockNo = CGEQUP_All.StockNo
WHERE CGEQUP_All.InventoryStatus IN ('H', 'R', 'I')
AND CGNOTE.NoteSeqNo > 0
0
 

Author Closing Comment

by:Majikthise
ID: 31505911
Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

783 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