You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT ...
FROM`base_type` a ;
SELECT*FROM (
SELECT a.`id`, a.`base_type_id`, a.`item_name`FROM`base_item` a
WHERE (a.`base_type_id`=2) LIMIT0,1
) ftb
UNION ALLSELECT*FROM (
SELECT a.`id`, a.`base_type_id`, a.`item_name`FROM`base_item` a
WHERE (a.`base_type_id`=3) LIMIT0,1
) ftb
UNION ALLSELECT*FROM (
SELECT a.`id`, a.`base_type_id`, a.`item_name`FROM`base_item` a
WHERE (a.`base_type_id`=4) LIMIT0,1
) ftb
UNION ALLSELECT*FROM (
SELECT a.`id`, a.`base_type_id`, a.`item_name`FROM`base_item` a
WHERE (a.`base_type_id`=5) LIMIT0,1
) ftb
The text was updated successfully, but these errors were encountered:
.LeftJoin((a, b) => b.Id == (freeSql.Select<BaseItem>().As("b2").OrderByDescending(b2 => b2.ID).Where(b2 => b2.BaseTypeId == a.Id).First(b2 => b2.Id)))
.ToSql((a, b) => new { a, b });```
有1对多 的关系,但是我需要取最近一条关联记录。这种是 左连接查询的。freesql 该如何处理呀
base_type1对base_item多,通过BaseTypeId 外键关联。
0.直接写sql
1. 使用LeftJoin
参考上面的sql,转成left join
生成的sql
2. 直接IncludeMany一对多。使用导航
生成的sql有点多,分开两次执行的:
The text was updated successfully, but these errors were encountered: