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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:48:06+00:00 2026-06-17T05:48:06+00:00

let’s say I have 5 tables, as follows: CREATE TABLE T1 ( FIRST_NAME VARCHAR2(100),

  • 0

let’s say I have 5 tables, as follows:

CREATE TABLE T1 (
FIRST_NAME VARCHAR2(100),
LAST_NAME VARCHAR2(100),
CITY NUMERIC,
SALARY NUMERIC);

CREATE TABLE T2 (
CITY NUMERIC,
DISTRICT  NUMERIC);

CREATE TABLE T3 (
DISTRICT NUMERIC,
DOMAIN NUMERIC);

CREATE TABLE T4 (
DOMAIN NUMERIC,
DETAILS_BOOK NUMERIC);

CREATE TABLE T5 (
DETAILS_BOOK NUMERIC,
FIRST_NAME VARCHAR2(100),
LAST_NAME VARCHAR2(100),
EMAIL VARCHAR2(100));

INSERT INTO T1 VALUES ('john', 'doe',1001,1000); 
INSERT INTO T1 VALUES ('jack', 'jill',1001,2000);
INSERT INTO T1 VALUES ('jeff', 'bush',1001,1500);

INSERT INTO T2 VALUES (1001,1);

INSERT INTO T3 VALUES (1,543);

INSERT INTO T4 VALUES (543,22);

INSERT INTO T5 VALUES (22,'john', 'doe','john@22.com');
INSERT INTO T5 VALUES (44,'john', 'doe','john@44.com');
INSERT INTO T5 VALUES (22,'jeff', 'bush','jeff@22.com');
INSERT INTO T5 VALUES (44,'jeff', 'bush','jeff@44.com');

now, I want all records from t1, with their salaries and emails, corresponding to tables t2, t3, and t4, such that the reuslt should be:

FIRST_NAME | LAST_NAME | SALARY | EMAIL
--------------------------------------------------
john       | doe       |  1000  | john@22.com
jeff       | bush      |  1500  | jeff@22.com
jack       | jill      |  2000  | (NULL)

what I got so far is:

SELECT T1.FIRST_NAME, T1.LAST_NAME,T1.SALARY,T5.EMAIL
FROM T1,T2,T3,T4,T5
WHERE   T1.FIRST_NAME = T5.FIRST_NAME (+)
and     T1.LAST_NAME = T5.LAST_NAME(+)
AND     T1.CITY = T2.CITY
AND     T2.DISTRICT = T3.DISTRICT
AND     T3.DOMAIN = T4.DOMAIN
AND     T4.DETAILS_BOOK = T5.DETAILS_BOOK

which returns only the first two rows.

  • 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-06-17T05:48:07+00:00Added an answer on June 17, 2026 at 5:48 am

    Try this instead:

    SELECT 
      T1.FIRST_NAME, 
      T1.LAST_NAME,
      T1.SALARY,
      T5.EMAIL
    FROM T1
    LEFT JOIN T2  ON T1.CITY         = T2.CITY
    LEFT JOIN T3  ON T2.DISTRICT     = T3.DISTRICT
    LEFT JOIN T4  ON T3.DOMAIN       = T4.DOMAIN
    LEFT JOIN T5  ON T4.DETAILS_BOOK = T5.DETAILS_BOOK
                 AND T1.FIRST_NAME   = T5.FIRST_NAME
                 AND T1.LAST_NAME    = T5.LAST_NAME;
    

    SQL Fiddle Demo

    This will give you:

    | FIRST_NAME | LAST_NAME | SALARY |       EMAIL |
    -------------------------------------------------
    |       john |       doe |   1000 | john@22.com |
    |       jeff |      bush |   1500 | jeff@22.com |
    |       jack |      jill |   2000 |      (null) |
    

    The problem is that the INNER JOIN after the OUTER JOIN makes your joins works like an INNER , because, the inner joins eliminate those unmatched rows coming from the outer joins.

    Note that: I used the ANSI SQL-92 explicit LEFT OUTER JOIN syntax, instead of the old implicit OUTER and INNER join syntax that you sued in your query.

    Please try to use the LEFT OUTER JOIN instead of the old outer join syntax, and avoid INNER JOIN after OUTER JOINs.

    For more details, see these:

    • Bad habits to kick : using old-style JOINs..

    • Bad habits to kick : using table aliases like (a, b, c) or (t1, t2, t3)


    Update:

    When you have many tables references in the FROM clause with the JOIN between them, each table is joined with the next table begging from the FROM clause1, results a temporary result set, then this temporary result set is joined with the next table and so on. In case of the OUTER JOIN, there are left or right:

    • LEFT JOIN will include those unmatched rows from the left table, where as,
    • RIGHT JOIN will include those unmatched rows from the right table.

    Depending on the data you want to select, you have to watch out those tables in the two sides of the JOIN operator and the order of them.


    1:This is just the logical query processing order, but in the actual order is always up to the query optimizer.

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

Sidebar

Related Questions

Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say I have some text as follows: do this, do that, then this,
Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say I have thousands of users and I want to make the passwords
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do

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.