我正在从2个表中选择数据。
$sql = "SELECT tb1.id, tb2.name FROM tblA tbl1 LEFT JOIN tblB tbl2 ON tb1.id = tbl2.studentID ORDER BY tbl1.id DESC LIMIT 20";
$statement = $con_db->prepare($sql);
我现在的问题是,我可以从tb1和tb2中的所有字段中选择自定义字段吗? e.g。
$sql = "SELECT tb1.id, tb1.subject, tb2.(*) FROM ....";
答案 0 :(得分:2)
您可以编写如下代码
$sql = "SELECT tb1.id, tb1.subject, tb2.* FROM tblA tbl1 LEFT JOIN tblB tbl2 ON tb1.id = tbl2.studentID ORDER BY tbl1.id DESC LIMIT 20";