examdb=# \d sample1 Table "test.sample1"
examdb=# \d sample1
Table "test.sample1"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
id | integer | | |
name | character varying | | |
tel | character varying(11) | | |
examdb=# SELECT * FROM sample1;
no | name | tel
----+------+-------------
1 | 佐藤 | 08012345678
2 | 田中 | 08022345678
3 | 山田 | 08032345678
4 | 佐藤 | 08042345678
(4 rows)
examdb=# SELECT id FROM (SELECT id FROM sample1) s1;
id
----
1
2
3
4
(4 rows)
examdb=# SELECT * FROM sample1 WHERE id =ANY (SELECT id FROM sample1 WHERE name = '佐藤');
id | name | tel
----+------+-------------
1 | 佐藤 | 08012345678
4 | 佐藤 | 08042345678
(2 rows)
examdb=# SELECT * FROM sample1 WHERE id = (SELECT id FROM sample1 WHERE name = '田中');
id | name | tel
----+------+-------------
2 | 田中 | 08022345678
(1 row)
examdb=# SELECT (SELECT id FROM sample1 WHERE name = '田中');
id
----
2
(1 row)
この記事が気に入ったらサポートをしてみませんか?