Solved

how to create an inner join

Posted on 2008-10-13
3
1,321 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
[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
3 Comments
 
LVL 5

Accepted Solution

by:
PaulKeating earned 125 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

635 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