2種類のレコードの共通の値を表すテーブルがあり、互いに異なるデータを保持する別の2つのテーブルがあります。テーブルのプライマリキーに基づいて2つのテーブルから選択
バンキング
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| officer | varchar(32) | NO | | NULL | |
| bank | varchar(64) | NO | | NULL | |
| branch | varchar(64) | NO | | NULL | |
| amount | int(11) | NO | | NULL | |
| date | date | NO | | NULL | |
| sys_date | date | NO | | NULL | |
| source_document | varchar(360) | NO | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
machinery_bankingをspare_parts_banking
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| banking_id | int(11) | NO | | NULL | |
| engine_no | varchar(64) | NO | | NULL | |
| chassis_no | varchar(64) | NO | | NULL | |
| receipt_number | varchar(64) | NO | | NULL | |
| payment_type | int(11) | NO | | NULL | |
+----------------+-------------+------+-----+---------+-------+
を以下のように表1である
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| banking_id | int(11) | NO | | NULL | |
| invoice_number | varchar(32) | NO | | NULL | |
+----------------+-------------+------+-----+---------+-------+
バンキングテーブルに入力された各データは、各テーブルmachinery_bankingまたはspare_parts_bankingのいずれかに他のデータがあります。
私はで、次のデータが
を次のようにがあるspare_parts_banking に+------------+-----------+------------+----------------+--------------+
| banking_id | engine_no | chassis_no | receipt_number | payment_type |
+------------+-----------+------------+----------------+--------------+
| 1 | 2324234 | NL234234 | RAN234 | 1 |
+------------+-----------+------------+----------------+--------------+
データをmachinery_bankingいる
+----+---------+------------+------------+-----------+------------+------------+------------------------------------------------------------------------------------------+
| id | officer | bank | branch | amount | date | sys_date | source_document |
+----+---------+------------+------------+-----------+------------+------------+------------------------------------------------------------------------------------------+
| 1 | prasad | Sampath | Kaduruwela | 234234234 | 2017-06-28 | 2017-06-28 | image |
| 2 | prasad | Commercial | Colombo | 234234234 | 2017-05-28 | 2017-05-28 | image |
+----+---------+------------+------------+-----------+------------+------------+------------------------------------------------------------------------------------------+
銀行テーブルに次のデータを持っています
+------------+----------------+
| banking_id | invoice_number |
+------------+----------------+
| 2 | INVRAN1 |
+------------+----------------+
私は
、私はどのようなクエリを使用することができます+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
| id | officer | bank | branch | amount | date | sys_date | engine_no | chassis_no | source_document | invoice_number |
+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
| 1 | prasad | Sampath | Kaduruwela | 234234234 | 2017-06-28 | 2017-06-28 | 2324234 | NL234234 | http://res.cloudinary.com/randeepa-com/image/upload/v1498455394/dmhxqal8hjcthhgav0n9.jpg | |
| 2 | prasad | Commercial | Colombo | 234234234 | 2017-05-28 | 2017-05-28 | | | http://res.cloudinary.com/randeepa-com/image/upload/v1498455394/dmhxqal8hjcthhgav0n9.jpg | INVRAN1 |
+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
を次のように私が取得を希望する結果が
+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
| id | officer | bank | branch | amount | date | sys_date | engine_no | chassis_no | source_document | invoice_number |
+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
| 1 | prasad | Sampath | Kaduruwela | 234234234 | 2017-06-28 | 2017-06-28 | 2324234 | NL234234 | http://res.cloudinary.com/randeepa-com/image/upload/v1498455394/dmhxqal8hjcthhgav0n9.jpg | INVRAN1 |
| 2 | prasad | Commercial | Colombo | 234234234 | 2017-05-28 | 2017-05-28 | 2324234 | NL234234 | http://res.cloudinary.com/randeepa-com/image/upload/v1498455394/dmhxqal8hjcthhgav0n9.jpg | INVRAN1 |
+----+---------+------------+------------+-----------+------------+------------+-----------+------------+------------------------------------------------------------------------------------------+----------------+
を次のクエリ
SELECT a.id, a.officer, a.bank, a.branch, a.amount, a.date, a.sys_date, b.engine_no, b.chassis_no, a.source_document, c.invoice_number
FROM banking a,machinery_banking b, spare_parts_banking c
WHERE a.id = b.banking_id OR a.id = c.banking_id;
を試してみましたが、次の結果を終了していますこの結果を得るには
これを行う? –