SQL多表联查

时间:2023-02-14 05:27:25

left join >>>外联

on >>>跟and一样使用,作为外联条件

表明后面加大写字母表示该表别名

例:

select A.*,B.name userName,B.sex from store A left join user B on B.id=A.useId where A.isDel=0 and B.isDel=0;

分页查询书写习惯:

String sql = "select * from ("

        + "select......from......(left join......on.....).where......"

        + ") t limit " + ((pageNumber-1) * SystemStateConstant.PAGENUM.intValue()) + "," + SystemStateConstant.PAGENUM.intValue() + "";

后面加的""是为了以后如果有添加字段可以用