javascript-mysql--How does an SQL statement query the list of user and user items?

Source: Internet
Author: User
I'm going to write a SQL to find all the user arrays, and then the Foreach Loop this array takes the ID to check all of his product data, there is no better way

Reply content:

I'm going to write a SQL to find all the user arrays, and then the Foreach Loop this array takes the ID to check all of his product data, there is no better way

The basic data of a commodity can be cached, especially with large traffic. The less the database goes, the better.
But the user to buy what goods or to go to the database good point is read-write separation

If the user ID has a foreign key, check with the left join.
If you don't have an index, this is the way to go.

The join statement can implement the

This at the same time take out to join, properly indexed, encapsulated into a stored procedure to tune, will be faster, I think if the traffic is large, the two logic apart, the front-end asynchronous take OK

Paging queries, such as 10 per page, get the ID array of the user.
Chaku can be used in (,....).
Of course, if access is frequent, it's best to add the cache

Create view as Select from join creates a views, pay attention to adding indexes, and then query as a table.

Generally speaking, users and products are bound to foreign keys. In this case, use Join (Leftjoin,rightjoin. ) can be taken out all at once. If the foreign key is not bound, then I suggest you may have to redesign the foreign key, after all, the foreign key in the user information update or delete automatically update or delete items.

  • 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: [email protected] 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.