473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Subquery Where or inner join and a left outer join

I have 2 tables (A and B), their setup is the same (datatypes of equivalent fields are the same)

Table A
ID A1 A2
1 1 $2.00
2 2 $3.00
3 3 $4.50
4 4 $4.75
5 4 $5.00
6 4 $6.00

Table B
ID B1 B2
1 1 $4.75
2 2 $4.50
3 3 $3.00
5 4 $2.00
6 4 $5.00
7 4 $6.00

What I want to achieve is a list of values of A2 that do not exist in B2, BUT only when the value of A1 = B1

A simple left outer join
SELECT A.A1, A.A2, B.B2
FROM A LEFT JOIN B ON A.A2 = B.B2
WHERE (((B.B2) Is Null));
will show A1=4 and A2 is $5.00, but that is not the result I am after.

It should show
A1 A2
1 $2.00
2 $3.00
3 $4.50
4 $4.75

I have been struggling to add an extra clause to the WHERE statement, but I get unhelpful errors.

Any suggestions ?
Dec 22 '16 #1

✓ answered by jforbes

I think all you need to do is include A1 and B1 in your Join:
Expand|Select|Wrap|Line Numbers
  1. FROM A LEFT JOIN B ON A.A1 = B.B1 AND A.A2 = B.B2

2 854
jforbes
1,107 Expert 1GB
I think all you need to do is include A1 and B1 in your Join:
Expand|Select|Wrap|Line Numbers
  1. FROM A LEFT JOIN B ON A.A1 = B.B1 AND A.A2 = B.B2
Dec 22 '16 #2
Thank you jforbes, that is the answer I was looking for.
Dec 22 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Thomas Beutin | last post by:
Hi, i've a speed problem withe the following statement: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id FROM ot_adresse AS a, ot_produkt AS p LEFT OUTER JOIN ot_kat_prod AS pz ON (...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
3
by: Doug | last post by:
Hi, I'm more familiar with MSSQL than Access syntax and have run into a problem with correctly putting ( )'s around the joins in a 3 table query. I want to INNER JOIN lenders and accounts and...
1
by: bob | last post by:
what's the difference between inner join and outer join in sql?
9
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
5
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
3
by: nico3334 | last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using LEFT OUTER JOIN. Here is an example of that query: SELECT a.supply, a.state, b.cost FROM Table1 a LEFT...
3
by: pbassutti | last post by:
Hello, I'm trying to link two tables... one for Employees and the other for Timecards I need to get a list of employees that do not have timecards on an SPECIFIC DATE I tried the follonwing
1
by: teneesh | last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
1
by: Manjunatht | last post by:
i need the answer for this question,in inner join we aren't using where clause in eqi join we are using where clause can u give me the answer?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.