Solved

how to create an inner join

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql case statement to calculate totals 5 32
why cannot i download this excel file? 7 27
split data by day 21 29
Color a cell based on a date in Excel 8 22
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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