我在sqllite浏览器中运行一个查询,输出正常。
但是当我通过Android的SqlLiteDatabase的rawQuery函数运行查询时,它会为每个原始行返回3行
查询是 -
select s.shout_id, u.user_id, u.image_id , u.firstname, u.lastname, s.shout_msg , i.user_id 'r_user_id' , i.image_id 'r_img_id', i.firstname 'r_firstname', i.lastname 'r_lastname', s.rec_time from shouts s left join users u
on s.user_id = u.user_id left join users i on s.reciever_id = i.user_id
where ((s.user_id =1 and s.reciever_id =2) or (s.user_id =2 and s.reciever_id =1) ) and s.shout_id < 5 order by s.shout_id desc limit 20;
原始查询代码在android -
中public Cursor get_friend_shouts_less(String myid, String friend_id, long shout_id) {
open();
Log.d("ListView1", "get less Message myid friend_id shout_id: " + myid + " " + friend_id + " " + shout_id );
Cursor c = db.rawQuery("select s.shout_id, u.user_id, u.image_id , u.firstname, u.lastname, s.shout_msg , i.user_id 'r_user_id' , i.image_id 'r_img_id', i.firstname 'r_firstname', i.lastname 'r_lastname', s.rec_time from shouts s left join users u " +
"on s.user_id = u.user_id left join users i on s.reciever_id = i.user_id" +
" where ((s.user_id =? and s.reciever_id =?) or (s.user_id =? and s.reciever_id =?) ) and s.shout_id < ? order by s.shout_id desc limit 60;", new String[]{myid, friend_id, friend_id, myid , String.valueOf(shout_id)});
return c;
}
答案 0 :(得分:0)
很高兴它有效,现在我的官方答案:
SQL LEFT JOIN操作等于karthesian产品AxB,它可以导致具有相同内容的行。在&#34; simple&#34;:使用GROUP BY合并那些相同的行。