Algorithmic problems with MySQL data reading

Source: Internet
Author: User
There's a couple more questions,
First read 1000 data from the Customer table,
From the order form, read out the latest order records for each of the 1000 customers,
From the service table, read the latest service records for each of the 1000 customers.
How should this code be written, which is the best solution?

Reply content:

There's a couple more questions,
First read 1000 data from the Customer table,
From the order form, read out the latest order records for each of the 1000 customers,
From the service table, read the latest service records for each of the 1000 customers.
How should this code be written, which is the best solution?

This means that you check the 1000 customers the latest transaction records, it is recommended to write down the latest order ID and service ID of each customer (you can consider using the cache, you can also add two fields directly in the user table), so that you can use in (IDs) to find out, 1000 memory requirements are not very large, Can be directly detected to traverse in the code.

# sqlselect * from order where order_id in (order_ids)# then phpforeach($orders as $order) {    foreach($customers as $customer) {        if ($customer->getCustomerId() == $order->getCustomerId()) {            //...        }    }}
  • 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.