Sergio Tapia
Sergio Tapia

Reputation: 41138

SQL Selecting rows that are in both tables

How can I select rows that exist is two tables. The intersection I guess? Any help?

ProductosA and ProductosB, they're both tables with the exact same number and type of columns.

How can I select the things that are inside of both using a single select statement?

Upvotes: 3

Views: 9353

Answers (5)

Hiep Pham
Hiep Pham

Reputation: 61

SELECT
  ProductosATable.* 
FROM
  ProductosATable 
  INNER JOIN ProductosBTable 
    ON ProductosATable.NAME = ProductosBTable.NAME 

Upvotes: 1

roman m
roman m

Reputation: 26521

select a.column1, a.column2
from productosA a
join
productosB b
on
a.id = b.id

that will give you what you want

Upvotes: 3

Rob Farley
Rob Farley

Reputation: 15849

Try:

select * from ProductosA
intersect
select * from ProductosB
;

Upvotes: 8

Murali VP
Murali VP

Reputation: 6417

If there is a primary/composite key join the two tables where the keys match, if there is no primary key, join them using where "and"ing match for each column.

Upvotes: 1

Ralph Lavelle
Ralph Lavelle

Reputation: 5769

Simply by specifying more than one table in your FROM clause you will get rows that exist in more than one table. Whether you get their entire rows, or just part of them, depends on how many of the columns you specify in the SELECT clause.

Upvotes: 0

Related Questions