5、Join 关联表查询
%%===============================================
%%   select y_info.* from y_account join y_info on (y_account.id = y_info.id)
%%      where y_account.account = 'xiaomin'
%%===============================================
%% 使用 qlc
F = fun() ->
Q = qlc:q([Y || X <- mnesia:table(y_account),
X#y_account.account =:= "xiaomin",
Y <- mnesia:table(y_info),
X#y_account.id =:= Y#y_info.id
]),
qlc:e(Q)
end,
mnesia:transaction(F).
  6、Limit 查询
%%===============================================
%%   select * from y_account limit 2
%%===============================================
%% 使用 qlc
F = fun() ->
Q = qlc:q([E || E <- mnesia:table(y_account)]),
QC = qlc:cursor(Q),
qlc:next_answers(QC, 2)
end,
mnesia:transaction(F).
  注:使用qlc模块查询,需要在文件顶部声明“-include_lib("stdlib/include/qlc.hrl").”,否则编译时会产生“Warning: qlc:q/1 called, but "qlc.hrl" not included”的警告。