0

I have two tables:

CREATE TABLE Master (
    url TEXT PRIMARY KEY,
    masterId TEXT,
);

CREATE TABLE Version (
    verId TEXT PRIMARY KEY,
    isPending INTEGER,
    masterId TEXT,
    FOREIGN KEY(masterId) REFERENCES Master(masterId)
);

I want to select all pending urls. Meaning all urls from Master that has a row in Version with the same masterId and isPending = 1.

How to write such nested select?

Sanich
  • 1,739
  • 6
  • 25
  • 43

2 Answers2

0

Use join

SELECT m.*
     , v.*
FROM   Master m
JOIN   version v
  ON m.masterId = v.masterId
WHERE  isPending = 1 
Kobi
  • 2,494
  • 15
  • 30
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
0

If you just need the URL's that are pending then you could use an EXISTS

SELECT url
FROM Master m
WHERE EXISTS
(
  SELECT 1
  FROM Version v
  WHERE v.masterId = m.masterId
    AND v.isPending = 1
);
LukStorms
  • 28,916
  • 5
  • 31
  • 45