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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:07:29+00:00 2026-05-19T04:07:29+00:00

When I have to select a number of fields from different tables: do I

  • 0

When I have to select a number of fields from different tables:

  1. do I always need to join tables?
  2. which tables do I need to join?
  3. which fields do I have to use for the join/s?
  4. do the joins effects reflect on fields specified in select clause or on where conditions?

Thanks in advance.

  • 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-19T04:07:29+00:00Added an answer on May 19, 2026 at 4:07 am

    Think about joins as a way of creating a new table (just for the purposes of running the query) with data from several different sources. Absent a specific example to work with, let’s imagine we have a database of cars which includes these two tables:

    CREATE TABLE car (plate_number CHAR(8), 
                      state_code CHAR(2), 
                      make VARCHAR(128), 
                      model VARCHAR(128),);
    
    CREATE TABLE state (state_code CHAR(2),
                        state_name VARCHAR(128));
    

    If you wanted, say, to get a list of the license plates of all the Hondas in the database, that information is already contained in the car table. You can simply SELECT * FROM car WHERE make='Honda';

    Similarly, if you wanted a list of all the states beginning with “A” you can SELECT * FROM state WHERE state_name LIKE 'A%';

    In either case, since you already have a table with the information you want, there’s no need for a join.

    You may even want a list of cars with Colorado plates, but if you already know that “CO” is the state code for Colorado you can SELECT * FROM car WHERE state_code='CO'; Once again, the information you need is all in one place, so there is no need for a join.

    But suppose you want a list of Hondas including the name of the state where they’re registered. That information is not already contained within a table in your database. You will need to “create” one via a join:

    car INNER JOIN state ON (car.state_code = state.state_code)
    

    Note that I’ve said absolutely nothing about what we’re SELECTing. That’s a separate question entirely. We also haven’t applied a WHERE clause limiting what rows are included in the results. That too is a separate question. The only thing we’re addressing with the join is getting data from two tables together. We now, in effect, have a new table called car INNER JOIN state with each row from car joined to each row in state that has the same state_code.

    Now, from this new “table” we can apply some conditions and select some specific fields:

    SELECT plate_number, make, model, state_name
    FROM car
    INNER JOIN state ON (car.state_code = state.state_code)
    WHERE make = 'Honda'
    

    So, to answer your questions more directly, do you always need to join tables? Yes, if you intend to select data from both of them. You cannot select fields from car that are not in the car table. You must first join in the other tables you need.

    Which tables do you need to join? Whichever tables contain the data you’re interested in querying.

    Which fields do you have to use? Whichever fields are relevant. In this case, the relationship between cars and states is through the state_code field in both table. I could just as easily have written

    car INNER JOIN state ON (state.state_code = car.plate_number)
    

    This would, for each car, show any states whose abbreviations happen to match the car’s license plate number. This is, of course, nonsensical and likely to find no results, but as far as your database is concerned it’s perfectly valid. Only you know that state_code is what’s relevant.

    And does the join affect SELECTed fields or WHERE conditions? Not really. You can still select whatever fields you want and you can still limit the results to whichever rows you want. There are two caveats.

    First, if you have the same column name in both tables (e.g., state_code) you cannot select it without clarifying which table you want it from. In this case I might write SELECT car.state_code ...

    Second, when you’re using an INNER JOIN (or on many database engines just a JOIN), only rows where your join conditions are met will be returned. So in my nonsensical example of looking for a state code that matches a car’s license plate, there probably won’t be any states that match. No rows will be returned. So while you can still use the WHERE clause however you’d like, if you have an INNER JOIN your results may already be limited by that condition.

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

Sidebar

Related Questions

I have need to select a number of 'master' rows from a table, also
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
Right now, I have SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT
I have a select statement with calculated columns and I would like to use
I have a table of vehicles with registration numbers, and want to select a
I have a select query that currently produces the following results: Description Code Price
I have a select control, and in a javascript variable I have a text
I want to have a select-only ComboBox that provides a list of items for
Suppose I have a SELECT statement that returns some set of results. Is there

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.