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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:12:01+00:00 2026-05-25T03:12:01+00:00

What i have is a union query that is returning two rows because of

  • 0

What i have is a union query that is returning two rows because of the column Outside. It returns a row as '' in the top half like its suppose to, and in the bottom half it returns the actual field that is found in the join. I basically need to have a '' row if there is nothing in the join. I understand union by nature dedupe, and i understand why this isn’t a dedupe, but i’m not sure how to get it so I only have the row in the join else have a ''.

SELECT Me, Ope, Dd,U11, Id3, Legal
       , PAI = (SELECT tbluser.user FROM tbluser WHERE tblmat.PAI = tbluser.userid)
       , Ial = (SELECT tbluser.user FROM tbluser WHERE tblmat.Id3 = tbluser.userid)
       , '' AS Outside, Dagal
FROM tblmat
WHERE MStatus = 'Open'
    AND (mgroup = 'Cas' OR templategroup = 'Sub' OR tmattertemplate = 'Ss')
    AND (Opte <= CONVERT (NCHAR (8), GETDATE (), 112)
    AND Opte >= DateADD (mm, -6, GETDATE ()))
    AND lookup2 IN('NOL','NH','NE')
UNION
SELECT Me, Ope, Dd, U11, Id3, Legal
       , PAI = (SELECT tbluser.user FROM tbluser WHERE tblmat.PAI = tbluser.userid)
       , Ial = (SELECT tbluser.user FROM tbluser WHERE tblmat.Id3 = tbluser.userid)
       , tblCon.ContactName AS Outside, Dagal
FROM    ttblmat
JOIN tblMatRelatedItems ON tblmat.me = tblMatRelatedItems.me
JOIN tblcon ON tblMatRelatedItems.relatedkey = tblcon.contactid
WHERE MStatus = 'Open'
    AND (mgroup = 'Cas' OR templategroup = 'Sub' OR tmattertemplate = 'Ss')
    AND (Opte <= CONVERT (NCHAR (8), GETDATE (), 112)
    AND Opte >= DateADD (mm, -6, GETDATE ()))
    AND lookup2 IN('NOL','NH','NE') 
    AND tblmatterRelateditems.RelatedItem = 'Contact'
    AND tblcontacts.contacttype = 'Managing Partner'
  • 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-25T03:12:01+00:00Added an answer on May 25, 2026 at 3:12 am

    You can use a single Left outer join and put you the constraints for the join in the in the on clause to accomplish your task

    SELECT
        Me,
        Ope,
        Dd,
        U11,
        Id3,
        Legal,
        PAI = (SELECT tbluser.user FROM tbluser WHERE tblmat.PAI = tbluser.userid),
        Ial = (SELECT tbluser.user FROM tbluser WHERE tblmat.Id3 = tbluser.userid),
        isnull(tblCon.ContactName,'') AS Outside,
        Dagal
    FROM
        ttblmat
    LEFT OUTER JOIN
        tblMatRelatedItems
    ON
        tblmat.me = tblMatRelatedItems.me and
        tblmatterRelateditems.RelatedItem = 'Contact'
    LEFT OUTER JOIN
        tblcon
    ON
        tblMatRelatedItems.relatedkey = tblcon.contactid and
        tblcon.contacttype = 'Managing Partner' 
    WHERE
        MStatus = 'Open' AND
        (mgroup = 'Cas' OR templategroup = 'Sub' OR tmattertemplate = 'Ss') AND
        (Opte <= CONVERT (NCHAR (8), GETDATE (), 112) AND
        Opte >= DateADD (mm, -6, GETDATE ())) AND
        lookup2 IN('NOL','NH','NE') 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an sql query that returns rows from two tables with same column
I have to write a query that performs a union between two tables with
I have a query that UNION 's two somewhat similar datasets, but they both
I have a query that performs a UNION between two tables. I'm trying to
I have a statement that looks like: QUERY A UNION QUERY B ORDER BY
I have two tables with some ID's and I need a query that returns
I have a query that uses a UNION ALL to return results from two
I have two IEnumerable collections that I would like to union. One selects news
I have the following query that returns a set of rows based on some
I have a union that is defined like this: typedef union { enum {

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.