Multi-table operation

1. Left join and multi-table query 

select t1.cardtype,t1.description,t1.enabled,t1.service,t2.CARD_TYPE_GROUP_NAME
from prepaid_remit_pccw_cardtype t1 left join PREPAID_REMIT_CARDTYPE_GROUP t2 on t1.card_type_group_id = t2.card_type_group_id order by t1.service,t1.cardtype

 

Difference:
All work of left join is based on left and left table prevail, so 
1 if left table is empty, then an empty record will be displayed 
2 if there is a record in left table that cannot be found in right table, the same This record will also be displayed 

Multi-table query is not the case, as long as there is no match in where, the record will not be displayed

select t1.cardtype,t1.description,t1.enabled,t1.service,t2.CARD_TYPE_GROUP_NAME
from prepaid_remit_pccw_cardtype t1 ,PREPAID_REMIT_CARDTYPE_GROUP t2 where t1.card_type_group_id = t2.card_type_group_id order by t1.service,t1.cardtype

 

2. Multi-table insert

Use a match statement:

insert into prepaid_remit_pccw_cardtype t (t.cardtype,t.enabled,t.description,t.service,t.card_type_group_id)
values (1,'Y','a','b',(select g.card_type_group_id from PREPAID_REMIT_CARDTYPE_GROUP g
where g.card_type_group_name='ab'))

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680129&siteId=291194637