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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:50:54+00:00 2026-05-17T15:50:54+00:00

I need to get data from 3 different tables. I know the basics about

  • 0

I need to get data from 3 different tables. I know the basics about JOINs but when it comes to more complicated queries like getting data from 3 or more tables using JOIN I get a little confused and I just start playing with the queries writing what make sense to me, like the next one:

SELECT movies.imdbID,
  movies.title,
  movies.year,
  movie_ratings.votes,
  movie_ratings.total_value,
  movie_ratings_external.votes,
  movie_ratings_external.total_value
FROM movies, movie_ratings_external
LEFT JOIN movie_ratings ON movie_ratings.imdbID = movie_ratings_external.imdbID
WHERE movies.imdbID = movie_ratings_external.imdbID
ORDER BY movie_ratings.votes DESC, movie_ratings_external.votes DESC
LIMIT 30

This query works. I get the selected fields from the correct tables and ordered the right way, but I think I’m mixing up things (like regular querying two tables and JOINing between two tables) and I’m sure theres a better/more efficient way to accomplish the same purpouse.

Any DB geek available?

  • 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-17T15:50:55+00:00Added an answer on May 17, 2026 at 3:50 pm

    Modified your query just a tad bit. Everything else was pretty much spot on.

    I am not exactly sure what you call a “regular query” but Joins are pretty much the very basic part of a regular query.

    In your old query, this part FROM movies, movie_ratings_external was basically a CROSS JOIN. Replaced it with a JOIN (i used a LEFT JOIN assuming that you always wanted to return all the movies but basic intention was that the CROSS JOIN with the filtering in the WHERE is a LOT more inefficient because you are manipulating more ROWS – especially unnecessary ones)

    Think of it this way. Every Join statement in your SELECT returns a set of row which are then JOINED with the next table in the JOIN. The idea should be to try an filter rows progressively with each join as far as possible so that you arent getting unnecessary tuples. Thats where the ON statements come in.

    Removed

    SELECT 
      movies.imdbID,
      movies.title,
      movies.year,
      movie_ratings.votes,
      movie_ratings.total_value,
      movie_ratings_external.votes,
      movie_ratings_external.total_value
    FROM movies 
    LEFT OUTER JOIN movie_ratings_external
         ON movies.imdbID = movie_ratings_external.imdbID
    LEFT JOIN movie_ratings 
         ON movie_ratings.imdbID = movie_ratings_external.imdbID
    ORDER BY movie_ratings.votes DESC, movie_ratings_external.votes DESC
    LIMIT 30
    

    Hope that helps!!

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

Sidebar

Related Questions

I have two different tables from which I need to pull data blogs which
I have an sql query pulling a few results from different tables, one of
I have an SQL query I get from a configuration file, this query usually
I am writing a fairly large and complex data analysis program and I have
I'm an amateur, admittedly so, but I'm having fun trying to learn a little
I need something real simple, that for some reason I am unable to accomplish
I'm inexperienced with sql in general, so using Hibernate is like looking for an
I want to use ms sql 2005 to send email reminders to my customers.
I am new to .NET 3/3.5 (C#) Programming. It may be simple for you
For simplicity I am going to use Northwind as an example... I would like

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.