mysql查询大于0的标记_MySQL如何查询回答数大于0的问题并分页
question表的字段:
question_id, title, content
answer表的字段
answer_id, question_id, content
百度了很久,參考著寫了兩條SQL語句:
select question.question_id, question.title from question inner join answer on question.question_id = answer.question_id
select question_id, title from question where (select count(answer.question_id) from answer where answer.question_id = question.question_id) > 0
第一條語句查詢用時1.23s,得到6604條結果,但是有明顯重復,前6個結果為:
第二條語句查詢用時34s,得到1188條結果,但是沒有重復,前6個結果為:
我在做一個小練習,想把回答數(shù)大于0的問題顯示在首頁,
請問各位大神,我的SQL語句要如何修改,才能得到回答數(shù)大于0的所有問題。
另外,我想剛開始在首頁顯示10個問題,看完了,再加載10個問題(當然這些問題都是要求回答數(shù)大于0的),這用SQL要怎么做?
總結
以上是生活随笔為你收集整理的mysql查询大于0的标记_MySQL如何查询回答数大于0的问题并分页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Docker学习笔记——Java及Tom
- 下一篇: centos xampp安装mysql_