写个三表关联求指点
表1 shop 字段 typeid userid
表2 user 字段 id
表3 type 字段 id
只有一个表2的 user.id 查询出来表1和表2里面的数据
1 select s.*, u.* 2 from user u 3 left join shop s on u.id = s.userid 4 where u.id = @id
@ミ輝じ☆﹎: 用left join做关联 http://www.w3schools.com/sql/sql_join_left.asp
感觉表1是关系表啊
只查询表1 和表2里的数据, 表3没什么用?
select a.*,b.* from [user] as a left join shop as b on a.id=b.userid where a.id='{0}'
--通过User表的Id,查询相关数据 SELECT [User].id, [TYPE].Id FROM [USER] LEFT JOIN shop ON shop.userId = [USER].Id LEFT JOIN [TYPE] ON shop.typeId = [TYPE].Id