A
A
Andrey Golubkov2015-01-23 12:21:15
SQL
Andrey Golubkov, 2015-01-23 12:21:15

How to search a Table using a condition from another table?

How can I write a SQL query like this
SELECT * FROM table1 WHERE id = table2.pid
So that I can select fields from table 1 where the ID value is equal to the PID value in table 2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RiON69, 2015-01-23
@RiON69

SELECT * FROM t1
WHERE id in (SELECT id FROM t2)

V
Vapaamies, 2015-01-23
@vapaamies

select
  t1.*
from
  table1 t1,
  table2 t2
where
  t1.id = t2.pid;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question