Query the username, psw, gname, and Tel of all realnames today.
Table Structure:
Table T1
Field name: t1_id, username, psw
Table T2
Field name: t2_id, gname, t1_id // here one t1_id corresponds to multiple t2_id
T3
Field name: t3_id, realname, tel, t1_id // here, a t1_id corresponds to a t3_id
The trouble is that when a realname has no content in Table T2, the username, psw, and Tel of this realname should be displayed and used directly.
SQL = "select username, psw, gname, tel from T1, T2, T3 where t1.t1 _ id = t2.t1 _ id and t1.t1 _ id = t3.t1 _ id"
The result is that the T2 table must have a realname file to query its information. This is definitely not the desired result. The SQL statement is as follows:
SQL = "select username, psw, gname, tel from (T1 left join T2 on t1.t1 _ id = t2.t1 _ id) left join T3 on t1.t1 _ id = t3.t1 _ id"
In this way, the desired result is obtained.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.