我想将两个查询连接到一个查询中。
在第一个查询中检索到的是列为resourceindex
的表,它按升序排序:
String loadRates = "SELECT * FROM ratings WHERE userindex="
+ uindex
+ " ORDER BY rank DESC";
在第二个查询中,应检索的是resourceindexes
:
String loadResources = "SELECT * FROM resourceinfo WHERE resourceindex = "
+ rs.getInt("resourceindex");
如何将这些组合成一个查询?
答案 0 :(得分:1)
SELECT ri.* FROM resourceinfo ri, ratings r
WHERE ri.resourceindex = r.resourceindex AND r.userindex = ?
ORDER BY r.rank DESC
答案 1 :(得分:1)
试试这个:
"SELECT * FROM public.resourceinfo, public.ratings WHERE "
+ "ratings.resourceindex = resourceinfo.index AND ratings.userindex = "
+ uindex
+ "ORDER BY ratings.rank DESC";