Query nesting in mysql

Source: Internet
Author: User
Query nesting of mysql. SQLcodeselecta. *, d. sell_countfromboroughasaleftjoin (selectda. * from (selectcount (db. id) assell_count, db. borough_idfromhousesellasdbwher mysql Query nesting problem.
SQL code
  Select. *, d. sell_countfrom borough as a left join (select da. * from (select count (db. id) as sell_count, db. borough_id from house1_as db where db. borough_id =. id) as da) as dwhere. is_checked = 1 order by id desc LIMIT 0, 10


In left join
An error is returned if where db. borough_id = a. id. Is there any way to implement it.



------ Solution --------------------
Change order by a. id to group
SQL code
SELECT. *, COUNT (db. id) AS sell_count FROM borough AS a left join house1_as db ON (db. borough_id =. id) WHERE. is_checked = 1 group by. idORDER BY id desc limit 0, 10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.