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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:12:41+00:00 2026-06-03T06:12:41+00:00

Is it anyhow possible to do a SQL query where you take some info

  • 0

Is it anyhow possible to do a SQL query where you take some info from left table and all info from right table matching the conditions.
BUT if there is no records matching the conditions in the right table, it should still show the full record, but filled with a lot of *NULL*s

At the moment, I have come to this:

select
 u.id, u.fullname,
 r.*
from
 users as u
right outer join
 rapports as r
on
 u.id = r.userid
where
 u.active = 1
 and (r.closed = 0 or CONVERT(varchar, r.periodstart, 112) = convert(varchar, GETDATE(), 112))
order by
 u.fullname

But this only shows records from user-table if there is a record in rapports-table matching the WHERE-conditions.

Is it anyhow possible?

  • 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-03T06:12:43+00:00Added an answer on June 3, 2026 at 6:12 am

    Notice where the conditions for the outer table (r) go – not in the WHERE clause (which converts your outer join to an inner join) but rather in the ON clause.

    select
     u.id, u.fullname,
     r.*
    from
     users as u
    left outer join
     rapports as r
    on
     u.id = r.userid
     and (r.closed = 0 
       or CONVERT(varchar, r.periodstart, 112) = convert(varchar, GETDATE(), 112))
    where
     u.active = 1
    order by
     u.fullname;
    

    However this is much better:

    select
     u.id, u.fullname,
     r.*
    from
     users as u
    left outer join
     rapports as r
    on
     u.id = r.userid
     and (r.closed = 0 or CONVERT(DATE, r.periodstart) = CONVERT(DATE, GETDATE()))
    where
     u.active = 1
    order by
     u.fullname;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it anyhow possible to merge 2 SQL logins, so that I can access
This may be rather noobish but I'm gonna ask anyhow. I have a class
Anyhow, I have a problem. A tiny problem I suppose, but one that's bugging
Possible Duplicate: Howto build a SQL statement with using IDs that might not be
I'm not even sure if this is possible, but I want to combine blind
So I wonder is it possible and how to pass socket from java to
Today I'm on an asking spree :P Anyhow... Right now I am developing a
I want to position my jQuery dialog x-pixels away from the right border of
I'm the same guy that asked: BEGIN/END and CREATE Table in single .sql file
I'm trying to test some of my php code but fail with mocking objects.

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.