Javascript-MYSQL -- how can I use an SQL statement to query the list of products of users and users?

Source: Internet
Author: User
Now I write an SQL statement to find out all the user groups, and then use the foreach loop to query all the product data with the id, I am writing an SQL statement to find out all the groups of users, and then using the foreach loop array to check all the product data with the id. There is no better way.

Reply content:

Now I am writing an SQL statement to find out all the user groups, and then the foreach loop this array takes the id to query all his product data, there is no better way

The basic data of commodities can be cached, especially when there is a large access volume. Obviously, the less the database goes, the better.
However, the user still needs to take the database for what they bought. The better thing is read/write splitting.

If the user ID has a foreign key, use left join to check it.
If no index is available, you can use this method.

The join statement can be implemented.

When this is obtained at the same time, join is required. If you add an index and encapsulate it into a stored procedure for adjustment, it will be faster. I think if there is a large amount of traffic, split the two logics, frontend asynchronous retrieval is fine

Query by PAGE, such as 10 entries per page, and get the user id array.
You can use in (1, 2, 3,...) to check the database ,....).
Of course, if the access is frequent, it is best to add Cache

Create view as select from join to create a view. Note that you can add an index and query it as a table.

Generally, users and products are bound with foreign keys. In this case, the use of join (leftjoin, rightjoin...) can be used to retrieve all data at a time. If no foreign key is bound, I suggest you re-design it. After all, the foreign key automatically updates or deletes the product in terms of user information update or deletion.

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.