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

  • Home
  • SEARCH
  • 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 334359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:02:48+00:00 2026-05-12T10:02:48+00:00

I have the following tables (I’ve simplified the data contained in the tables). RateTable

  • 0

I have the following tables (I’ve simplified the data contained in the tables).

RateTable
- rate_table_id [int]
- rate_table_name [nvarchar(50)]

RateTableUsed
- rate_used_id [int]
- rate_table_id [int] (key to RateTable.rate_table_id)
- customer_id [int] 

RateTableExtra
- rate_table_extra_id [int]
- rate_ extra_id [int] (key to RateExtra.rate_table_id)
- rate_used_id [int] (key to RateTableUsed.rate_used_id)

RateExtra
- rate_ extra_id [int]
- rate_extra_name [nvarchar(50)]


select rate_table_name, rate_table_extra_id, rate_extra_name from RateTableUsed rtu 
    innerjoin RateTable rt on rtu.rate_table_id = rt.rate_table_id 
    innerjoin RateTableExtra rte on rte.rate_table_id = rt.rate_table_id
    innerjoing RateExtr re on rte.rate_extra_id = re.rate_extra_id

The RateExtra contains only 3 values with key’s 1, 2 & 3 and names’ petrol surcharge, management fee and GST.

This is working fine for it’s current purpose. A list of values is being displayed with matching records and the RateExtra is queried only for the rate_extra_name.

So I may have the following results:

  • Ratetable1, 1, PetrolSurcharge
  • Ratetable1, 2, ManagementFee
  • Ratetable2, 3, PetrolSurcharge
  • Ratetable4, 4, GST
  • Ratetable6, 5, PetrolSurcharge

I’ve been asked to modify this so that each record that returns now includes records for each value in the RateExtra table. If there are no matching records then data from my RateTableExtra table should come back as NULL. So my data should come back as:

  • Ratetable1, 1, PetrolSurcharge
  • Ratetable1, 2, ManagementFee
  • Ratetable1, NULL, GST
  • Ratetable2, 3, PetrolSurcharge
  • Ratetable2, NULL, ManagementFee
  • Ratetable2, NULL, GST
  • Ratetable4, NULL, PetrolSurcharge
  • Ratetable4, NULL, ManagementFee
  • Ratetable4, 4, GST
  • Ratetable6, 5, PetrolSurcharge
  • Ratetable6, NULL, ManagementFee
  • Ratetable6, NULL, GST

I’ve tried OUTER joins but they don’t seem to be working I’m assuming because the RateExtra data is linked to the RateTableExtra which would return null. I’m now considering creating a dynamic query that will get my original result set, iterate over it checking for rate_extra_id and, if it’s not already in the resultset, appending a new row to the results with NULL data where I need it. I’m assuming this would work but I’ve got a feeling it’d be a killer on performance.

Is there any better way to do this? Hope someone can help, it’d be really appreciated.

  • 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-12T10:02:49+00:00Added an answer on May 12, 2026 at 10:02 am

    Try this:

    select 
        rate_table_name, 
        rate_table_extra_id, 
        rate_extra
    from 
        RateTableUsed rtu
        inner join RateTable rt on
            rtu.rate_table_id = rt.rate_table_id
        cross join RateExtra re
        left outer join RateTableExtra rte on 
            rte.rate_table_id = rt.rate_table_id
            and rte.rate_extra_id = re.rate_extra_id
    order by rt.rate_table_name, re.rate_extra_id
    

    What you’re getting with this query is, essentially, a Cartesian Join between RateTable and RateExtra, with a left join to find the values of RateTableExtra that match those pairs. Essentially, this query is bringing back all possible combinations of RateTable and RateExtra, and showing you which ones you have in your RateTableExtra table quickly.

    Be careful with Cartesian Joins. They can get out of hand very quickly with reasonably sized tables!
    Enjoy!

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

Sidebar

Related Questions

I have the following tables: Cateogories CategoryID (int) Primary Key CategoryName (varchar) Items ItemID
I have the following tables: **Product** ProdID int ProdOwner (nvarchar) Views int **Reviews** RevID
I have following tables: Profiles: ProfileID (Primary Key) ProfileName, etc. Contacts: ContactID (Primary Key)
I have following tables: **visitors** +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
I have following tables (CustomerType, Customer and Company) in a data base: In asp.net,
I have the following tables: Table A: id int v1 string v2 string Table
I have the following tables: Post Id int User Id int Then I have
I have the following tables CREATE TABLE IF NOT EXISTS `user` ( `id` int(11)
I have the following tables (example) t1 (20.000 rows, 60 columns, primary key t1_id)

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.