incident テーブル
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| title | varchar(1000) | YES | | NULL | |
| owner | int(11) | YES | | NULL | |
+-------+---------------+------+-----+---------+-------+
owner テーブル
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(1000) | YES | | NULL | |
+-------+---------------+------+-----+---------+-------+
incident テーブルと owner テーブルを結合する。
SELECT i.id, i.title, o.name FROM `incident` AS i RIGHT JOIN (SELECT id, name FROM `owner`) AS o ON i.owner = o.id
0 件のコメント:
コメントを投稿