Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:13:48+00:00 2026-05-27T01:13:48+00:00

Imagine a table for articles. In addition to the main query: SELECT * From

  • 0

Imagine a table for articles. In addition to the main query:

SELECT * From articles WHERE article_id='$id'

We also need several other queries to get

SELECT * FROM users WHERE user_id='$author_id' // Taken from main query

SELECT tags.tag 
FROM tags 
  INNER JOIN tag_map 
    ON tags.tag_id=tag_map.tag_id 
WHERE article_id='$id'

and several more queries for categories, similar articles, etc

Question 1: Is it the best way to perform these queries separately with PHP and handle the given results, or there is way to combine them?

Question 2: In the absence of many-to-many relationships (e.g. one tag, category, author for every article identified by tag_id, category_id, author_id); What the best (fastest) was to retrieve data from the tables.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:13:49+00:00Added an answer on May 27, 2026 at 1:13 am

    If all the relationships are one-many then you could quite easily retrieve all this data in one query such as

    SELECT
        [fields required]
    FROM
        articles a
        INNER JOIN
            users u ON a.author_id=u.user_id
        INNER JOIN 
            tag_map tm ON tm.article_id=a.article_id
        INNER JOIN
            tags t t.tag_id=tm.tag_id
    WHERE
        a.article_id='$id'
    

    This would usually be faster than the three queries separately along as your tables are indexed correctly as MySQL is built to do this! It would save on two round trips to the database and the associated overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine a table with GUIDs as primary key. I would like to select a
Imagine a table that has two fields, a smalltimedate and an int and about
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Imagine the following table (called TestTable ): id somedate somevalue -- -------- --------- 45
Imagine the following tables: create table boxes( id int, name text, ...); create table
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
Imagine you have a normal table view where each row is an item on
Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY
What is the best way to track changes in a database table? Imagine you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.