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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:10:29+00:00 2026-05-26T18:10:29+00:00

I want to select values from three tables. Each table has an buyer_entity_id column.

  • 0

I want to select values from three tables. Each table has an buyer_entity_id column.

I’ve come up with the syntax to do an outer join on two of the tables, but how to add the third table is eluding me.

Here’s the statement for the two table join which works exactly how I want it to work:

select * from (select  b.buyer_entity_id, count(distinct(a.row_id)) as imps 
from imps a, anl_line b
where b.line_item_id=a.buyer_line_id 
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab1
full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as clicks 
from clicks a, anl_line b 
where a.buyer_line_id=b.line_item_id 
and a.entity_id=3
group by b.buyer_entity_id 
order by b.buyer_entity_id) tab2
on tab1.buyer_entity_id = tab2.buyer_entity_id;

The third table would have an identical select statement and would also be joined on the buyer_entity_id value as well. However, when I add the third select statement I’m getting a “missing keyword” error. Below is my three way full outer join statement:

select * from ((select  b.buyer_entity_id, count(distinct(a.row_id)) as imps 
from imps_table a, line_table b
where b.line_item_id=a.buyer_line_id 
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab1
full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as clicks 
from clicks_table a, line_table b 
where a.buyer_line_id=b.line_item_id 
and a.entity_id=3
group by b.buyer_entity_id 
order by b.buyer_entity_id) tab2)
outer join (select  b.buyer_entity_id, count(distinct(a.row_id)) as vers 
from vers_table a, line_table b
where b.line_item_id=a.buyer_line_id 
and a.entity_id=3
group by b.buyer_entity_id
order by  b.buyer_entity_id) tab3
on tab1.buyer_entity_id = tab2.buyer_entity_id and tab2.buyer_entity_id=tab3.buyer_entity_id;
  • 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-26T18:10:30+00:00Added an answer on May 26, 2026 at 6:10 pm

    The error is here: order by b.buyer_entity_id) tab2). You need an on clause to specify the join condition between tab1 & tab2. order by b.buyer_entity) tab1 on <join condition)

    Once that is fixed. You will need to add full to the next line so that outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as vers becomes full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as vers.

    That covers syntax issues, but not semantic issues.

    Joins are pair wise table 1 is joined to table 2 on some condition, then the results of that becomes the left side to the next join. What do you want to have happen if tab1 and tab3 match, but tab2 does not? I’d guess produce a row with tab1 and tab3 data and tab2 nulls. Something like:

    select * 
    from (select  b.buyer_entity_id, count(distinct(a.row_id)) as imps 
            from imps_table a, line_table b
            where b.line_item_id=a.buyer_line_id 
            and a.entity_id=3
            group by b.buyer_entity_id) tab1
    full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as clicks 
            from clicks_table a, line_table b 
            where a.buyer_line_id=b.line_item_id 
            and a.entity_id=3
            group by b.buyer_entity_id) tab2
        on tab1.buyer_entity_id = tab2.buyer_entity_id
    full outer join (select  b.buyer_entity_id, count(distinct(a.row_id)) as vers 
            from vers_table a, line_table b
            where b.line_item_id=a.buyer_line_id 
            and a.entity_id=3
            group by b.buyer_entity_id) tab3
        on tab3.buyer_entity_id in (tab1.buyer_entity_id, tab2.buyer_entity_id)
    order by coalesce(tab1.buyer_entity_id
        , tab2.buyer_entity_id
        , tab3.buyer_entity_id);
    

    Also, please lose the order by in the subqueries. They are not doing anything for you, since the order is not guaranteed to survive the joins.

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

Sidebar

Related Questions

<select name="select"> </select> I want to populate the above tag with values from database.
Basically I want to alter the boolean value selecting from the table: e.g.: SELECT
i have users table and i have posts table i want select from users
I'm trying to get column names from a table. I want to supply the
I have a table of posts, each post has an IP address, I want
I want to do an SQL join query. I have three tables _A, _B,
With Perl's WWW::Mechanize module, I want to select a random value from a select
Say I have y distinct values and I want to select x of them
I want to implement chained select boxes: the first select box determines the values
In a SELECT statement I want to convert values to strings ie. SELECT TO_STRING(value).

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.