-1

I have two tables (A and B) with two columns in common (x and y). I'd like to inner join A and B on x but keep only the values of A's column y (the left join). I'm looking for a way that will combine the two y columns (can't just specify A.y in the select statement). How can I do this?

Example

Table A

x  y
1  2
3  4
5  6
7  8

Table B

x  y
1  2
3  8
9  null
11 0

I'd like the resulting table to look like

x  y
1  2
3  4
Andrew
  • 2,519
  • 6
  • 29
  • 46

3 Answers3

1
select a.x, a.y
from TableA a
inner join TableB b on a.x = b.x
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
0

Do you mean:

SELECT *
FROM A
INNER JOIN B b1 ON A.x = b1.x
LEFT JOIN B b2 ON a.y = b2.y
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
0

Take a look at SQL exclude a column using SELECT * [except columnA] FROM tableA? Second answer. Not the best solution, but you can use this as a workaround. In general, you should specify the full list of columns explicitly.

Community
  • 1
  • 1
Artur Udod
  • 4,465
  • 1
  • 29
  • 58