Javascript-mysql getting problems

Source: Internet
Author: User


The problem I encountered was: to get the first picture in the Project_id field, the Pic_url field. But how do I get the project_id is the field of the 27 Pic_url, and so on to get to the first picture of 28,29,30?
Two details:
The appearance of the picture is not always the first;
Get three pictures of three project_id, no longer need pictures in the back.

Thank

Reply content:


The problem I encountered was: to get the first picture in the Project_id field, the Pic_url field. But how do I get the project_id is the field of the 27 Pic_url, and so on to get to the first picture of 28,29,30?
Two details:
The appearance of the picture is not always the first;
Get three pictures of three project_id, no longer need pictures in the back.

Thank

MySQL database allows group to select non-group fields

But it's not the 1th one, not very clear.

select  project_id, pic_urlfrom    picswhere   pic_url is not nullgroup    by  project_id;

But since there's a self-increment ID,

You can min(id) find the minimum ID that meets the criteria, then connect the query to get the data you need.

select  b.*from    (        select  project_id, min(id) as id        from    pics        where   pic_url is not null        group            by  project_id        ) a    left join pics b on a.id = b.id;
  • Related Article

    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.