举例说明,下面不同的sql语句:
select u.id as userId, userName, tel, p.id as productId
from user1 u left join Transaction1 t on t.user_id= u.id
left join Product1 p on p.id = t.product_id
where u.id=1
结果:
select u.id, userName, tel, p.id
from user1 u left join Transaction1 t on t.user_id= u.id
left join Product1 p on p.id = t.product_id
where u.id=1
结果:
总结:不用as的话,查询不会报错,只是查询结果的阅读性比较差。
NB: 另外,在mybatis中,需要使用as,因为as的对象比如userId,在resultMap的“column”对象中还要使用,总不能写一个u.id在其中吧。