PostgreSQL - SUB_QUERY

DataBase 2009. 5. 2. 16:52


SUB-QUERY
-- simple sub-query
SELECT title FROM books WHERE author_id=(SELECT id FROM authors WHERE last_name='Geisel' AND first_name='Theodor Seuss');

-- sub-query using IN
SELECT title FROM books WHERE author_id IN (SELECT id FROM authors WHERE last_name ~ '^[A-E]');

-- multi-column sub-query using IN
SELECT isbn, cost, retail FROM stock
    WHERE (isbn, stock)
    IN (SELECT isbn, 0 FROM editions
        WHERE type='p');

'DataBase' 카테고리의 다른 글

PostgreSQL - FOREIGN KEY  (0) 2009.05.02
PostgreSQL - VIEW  (0) 2009.05.02
PostgreSQL - DELETE  (0) 2009.05.02
PostgreSQL - UPDATE  (0) 2009.05.02
PostgreSQL - SELECT  (0) 2009.05.02
Posted by bloodguy
,