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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:10:42+00:00 2026-05-13T02:10:42+00:00

I have several tables (to be exact, 7) tables I cross join in one

  • 0

I have several tables (to be exact, 7) tables I cross join in one another. This part gives me some problems;

Table “Actions”

 -----------------------------------------
| ID | Package ID | Action Type | Message |
 -----------------------------------------
| 40 | 100340     | 0           | OK      |
| 41 | 100340     | 12          | Error   |
| 42 | 100340     | 2           | OK      |

| 43 | 100341     | 4           | OK      |
| 44 | 100341     | 0           | Error   |
| 45 | 100341     | 12          | OK      |
 -----------------------------------------

Table “Packages”

 ----------------------
| ID     | Name        |
 ----------------------
| 100340 | Testpackage |
| 100341 | Package xy  |
 ----------------------

I accomplished cross joingin thm, but when there is no Package with an ID specified in Actions, all actions on that package are completely missing, rather than just leavin Name blank – which is what I’m trying to get.

So, if a reference is missing, just leave the corresponding joined column blank or as an empty string…:

 ----------------------------------------------------------------------
| Package ID | Name        | Action 0 | Action 2 | Action 4 | Action 12 |
 ----------------------------------------------------------------------
| 100340     | Testpackage | OK       | OK       |          | Error     |
| 100341     | Package xy  | Error    |          | OK       | OK        |
 ----------------------------------------------------------------------

How is that possible?

Edit

Sorry, I just saw my example was completety wrong, I updated it how it should look like in the end.

My current query looks something like this (as said above, just an extract as the actual one is about three times as long including even more tables)

SELECT
 PackageTable.ID AS PackageID,
 PackageTable.Name,
 Action0Table.Message  AS Action0,
 Action2Table.Message  AS Action2,
 Action4Table.Message  AS Action4,
 Action12Table.Message AS Action12
FROM
 Packages AS PackageTable LEFT OUTER JOIN
  Actions AS Action0Table ON PackageTable.ID  = Action0Table.PackageID LEFT OUTER JOIN
  Actions AS Action2Table ON PackageTable.ID  = Action2Table.PackageID LEFT OUTER JOIN
  Actions AS Action4Table ON PackageTable.ID  = Action4Table.PackageID LEFT OUTER JOIN
  Actions AS Action12Table ON PackageTable.ID = Action12Table.PackageID
WHERE
 Action0Table.ActionType  = 0 AND
 Action2Table.ActionType  = 2 AND
 Action4Table.ActionType  = 4 AND
 Action12Table.ActionType = 12
  • 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-13T02:10:43+00:00Added an answer on May 13, 2026 at 2:10 am

    As what the others has said, I have the same answer.

    Just showing u the different result

    declare @Actions table(id int , packageid int, actiontype int,dt date)
    declare @Packages table(id int,name varchar(50))
    insert into @Actions 
        select 40,100340,0,'2009/01/01 3:00pm' union all
        select 41,100340,12,'2009/01/01 5:00pm' union all
        select 42,100340,2,'2009/01/01 5:30pm' union all
        select 43,100341, 4,'2009/01/02 8:00am'
    insert into @Packages 
        select 100340,'Testpackage'
    

    Left outer join query

    select a.packageid,p.name,a.actiontype,a.dt
    from @Actions a
    left join @Packages p
    on a.packageid = p.id
    

    Full join(in this case u will get the same result)

    select a.packageid,p.name,a.actiontype,a.dt
    from @Actions a
    full join @Packages p
    on a.packageid = p.id
    

    Output:

    packageid   name    actiontype  dt
    100340  Testpackage 0   2009-01-01
    100340  Testpackage 12  2009-01-01
    100340  Testpackage 2   2009-01-01
    100341  NULL    4   2009-01-02
    

    Inner join query(which u don’t want)

    select a.packageid,p.name,a.actiontype,a.dt
    from @Actions a
    join @Packages p
    on a.packageid = p.id
    

    Output:

    packageid   name    actiontype  dt
    100340  Testpackage 0   2009-01-01
    100340  Testpackage 12  2009-01-01
    100340  Testpackage 2   2009-01-01
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several tables, books, bookcategories, categories bookcategories is a join table to allow
I have several tables in a database. One table (tbl_transactions) has thousands of orphaned
I have several tables: CREATE TABLE [dbo].[Tracks]( [Id] [uniqueidentifier] NOT NULL, [Artist_Id] [uniqueidentifier] NOT
I have several sources of tables with personal data, like this: SOURCE 1 ID,
I have several tables which looks like these below: <table id=table1> <tr> <th>Item</th> <th>Price</th>
I have a several tables nested within a table that I am parsing using
I have several tables that contain several strings for fields. Some of these fields
I have several tables: table user: id firstname lastname 1 John Doe 2 Jane
I have several tables 1 contacts and multiple data. Contacts has an ID field
I have several tables that I am selecting data from. I am trying to

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.