Solved

how to create an inner join

Posted on 2008-10-13
3
1,310 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

752 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