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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:11:28+00:00 2026-06-17T16:11:28+00:00

The below SQL query is working for me, but it returns the property value

  • 0

The below SQL query is working for me, but it returns the property value when there staffNo is null 6 times(Once for each staff member). I want to return the property owner even if the staffNo is null, without 6 returns.

SELECT s.branchNo, s.staffNo, s.fName, s.lName, propertyNo, p.staffNo,
       o.fName, o.lName, o.ownerNo
  FROM staff s, propertyforrent p, privateowner o
 WHERE s.staffNo = p.staffNo AND o.ownerNo = p.ownerNo
    OR p.staffNo IS NULL     AND o.ownerNo = p.ownerNo
 ORDER BY s.branchNo, s.staffNo, propertyNo

Results

B003    SG14    David   Ford    PG16    SG14    Tony    Shaw    CO93
B003    SG14    David   Ford    PG4     NULL    Tina    Murphy  CO40
B003    SG37    Ann     Beech   PG21    SG37    Carol   Farrel  CO87
B003    SG37    Ann     Beech   PG36    SG37    Tony    Shaw    CO93
B003    SG37    Ann     Beech   PG4     NULL    Tina    Murphy  CO40
B003    SG5     Susan   Brand   PG4     NULL    Tina    Murphy  CO40
B005    SL21    John    White   PG4     NULL    Tina    Murphy  CO40
B005    SL41    Julie   Lee     PG4     NULL    Tina    Murphy  CO40
B005    SL41    Julie   Lee     PL94    SL41    Carol   Farrel  CO87
B007    SA9     Mary    Howe    PA14    SA9     Joe     Keogh   CO46
B007    SA9     Mary    Howe    PG4     NULL    Tina    Murphy  CO40

Here is the desired result

B003    SG14    David   Ford    PG16    SG14    Tony    Shaw    CO93
B003    SG14                    PG4     NULL    Tina    Murphy  CO40
B003    SG37    Ann     Beech   PG21    SG37    Carol   Farrel  CO87
B003    SG37    Ann     Beech   PG36    SG37    Tony    Shaw    CO93
B005    SL41    Julie   Lee     PL94    SL41    Carol   Farrel  CO87
B007    SA9     Mary    Howe    PA14    SA9     Joe     Keogh   CO46

Thanks in advance!

  • 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-17T16:11:28+00:00Added an answer on June 17, 2026 at 4:11 pm

    Using a left join may be helpful

    SELECT s.branchNo, s.staffNo, s.fName, s.lName, propertyNo, p.staffNo,
           o.fName, o.lName, o.ownerNo
      FROM privateowner o
      LEFT JOIN propertyforrent p ON o.ownerNo = p.ownerNo
      LEFT JOIN staff s ON s.staffNo = p.staffNo
    
     ORDER BY s.branchNo, s.staffNo, propertyNo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is a working SQL query that returns a list of unviewed message counts
Below SQL query works when the spaces in the role name are replaced by
I have an SQL query (below) that essentially takes a student from tbStudents, and
This might be a very simple thing. Check out the normal sql query below
I have a T-SQL query as below which queries a table holding the search
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOID
Please explain the SQL query given below. I m new with SQL and struggling
How can I optimize below SQL (simplified view of my complex query.) Ideally, I

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.