Ask SQL statements to query one-to-multiple pages in multiple tables

Source: Internet
Author: User
For more information, see SQL statements.

Topic, field to_id to_title

Knowledge Point Table tag, field t_id t_title

Join table relation, field to_id t_id

Each question can have multiple knowledge points


The search box is provided on the web interface. you can select more knowledge points for 10 questions on each page. The problem is that there are duplicate data.

Select topic. to_id, topic. to_title from topic, relation where (topic. to_id = relation. to_id) and (t_id in (1, 2, 3 ));



Now, if the knowledge points 1, 2, and 3 are corresponding to the to_id of 1, three identical questions will appear. However, if the repetition is removed, it is in conflict with 10 entries on each page. I would like to ask the seniors about the related SQL statements. thank you very much !!!


Reply to discussion (solution)

Select distinct (topic. to_id, topic. to_title) from topic, relation, tag where (topic. to_id = relation. to_id) and (t_id in (, 3) limit;

Use group

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.