 |
ขอตัวอย่างการ join 3 ตารางแบบนี้หน่อยครับ ผล คือ ตาราง ผลลัพธื |
|
 |
|
|
 |
 |
|
id_run มันอยู่ตารางไหนหว่า
inner join ธรรมดาเองนะ
เบสิคๆ เลย
Code (PHP)
SELECT tb1.id_customer,tb1.name,tb2.num_a FROM T_customer tb1
INNER JOIN T_A tb2 ON tb1.id_customer=tb2.id_customer
LEFT JOIN T_B tb3 ON tb1.id_cutomer=tb3.id_customer
ลองเอาไปศึกษาปรับเปลี่ยนดูนะ
ปล.สอบอ่ะป่าว
|
 |
 |
 |
 |
Date :
2017-09-15 15:05:34 |
By :
Pong Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ union all ร่วมด้วย
Code (SQL)
SELECT @rowno:=@rowno+1 id_run,id_customer, name, num_
FROM (
select id_customer, num_a from table_a
union all
select id_customer, num_b from table_b
) as uni
, tablename as tb
, (select @rowno:=0) as rn
where tb.id_customer = uni.id_customer
|
 |
 |
 |
 |
Date :
2017-09-15 15:39:13 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดู error ให้ออก เป็นพื้นฐานในการเขียนโปรแกรมเลยนะ
|
 |
 |
 |
 |
Date :
2017-09-18 12:13:21 |
By :
ten1312 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|