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 3441098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:30:40+00:00 2026-05-18T08:30:40+00:00

Suppose I have a database which contains blog posts which have tags and I

  • 0

Suppose I have a database which contains blog posts which have tags and I want to retrieve a blog post with its tags.

I can do two queries:

SELECT title, text, date 
  FROM POSTS 
 WHERE id = 1

and

SELECT tag 
  FROM TAGS 
 WHERE post_id = 1

However I can also do it in a single query:

SELECT title, text, date, tag 
  FROM POSTS, TAGS 
 WHERE posts.id = 1 
  AND tags.post_id = posts.id

The latter is a bit wasteful, because it transfers the same title, text and date columns as many times as many tags the blog post have, but it may be faster, because there is only one trip to the server.

Is there some alternative for the latter query which avoids transferring duplicate data? Or is it not a big deal and I should use it anyway, because transferring a few hundred unused extra bytes is cheaper than making two separate queries?

  • 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-18T08:30:40+00:00Added an answer on May 18, 2026 at 8:30 am

    MySQL optimization isn’t quite as straightforward as this. You’ll find that sometimes multiple queries (possibly with a temp table in the middle) is much faster than a single query, especially with complex joins / aggregations going on. So, don’t assume that a single query will always be faster, because it won’t.

    However, a single query is often just as fast or faster than multiple queries, and it expresses what you’re doing much more succinctly. Don’t worry about a handful of bytes across the wire, they are trivial in comparison to everything else that’s going on.

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

Sidebar

Related Questions

I have a user table in my database which contains two columns FirstName and
Suppose I have an ASP.NET website running with its corresponding web.config file, which contains
Suppose I have two queries on a database table. The queries are defined in
I have a table with a field which contains strings in my MySQL database.
Suppose I have ten cron jobs running in parallel which fetch entries from database
I've a SmartGWT application which interacts with a mysql database using rpc services. Suppose
Is it possible to have selective queries in PostgreSQL which select different tables/columns based
I have a database which has an application role. The role members all belong
I have a database table, with people identified by a name, a job and
Suppose you have a large file made up of a bunch of fixed size

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.