(columns name)
b_Users = id,users_id,ac_num,bills
r_Users = id,users_id,ac_num,bills
f_users = id,users_id,name,address
f_users table:
id ----users_id---- name ---- address
1 12/1 A ad1
2 13/2 B ad2
3 14/1 C ad3
b_Users table:
id ---- users_id ---- ac_num ---- bills
1 12/1 1234 10$
2 14/1 1235 12$
r_Users table:
id ---- users_id ---- ac_num ---- bills
1 13/2 1238 19$
我想选择(users_id,name,address,ac_num,bills)
我使用了Join,但显示空字段。我不知道为什么。
答案 0 :(得分:1)
我在union all
和b_users
之间查询r_users
,然后加入users
:
SELECT f.users_id, name, address, ac_num, bills
FROM (SELECT b.users_id, ac_num, bills
FROM b_users b
UNION ALL
SELECT r.users_id, ac_num, bills
FROM r_users r) t
JOIN f_users f on f.users_id = t.users_id