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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:39:00+00:00 2026-06-15T00:39:00+00:00

I want to get data if orgid = 2 or if there is no

  • 0

I want to get data if orgid = 2 or if there is no row at all for the uid. orgid is an integer. The closest thing I could think of is to do IS NULL but I’m not getting data for the uid that doesn’t have an orgid row. Any idea?

select u.uid,u.fname,u.lname from u 
inner join u_org on u.uid = u_org.uid 
inner join login on u.uid = login.uid 
where u_org.orgid=2 or u_org.orgid is NULL 
and login.access != 4;

Basically the OR is if u_org.orgid row doesn’t exist.

  • 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-15T00:39:01+00:00Added an answer on June 15, 2026 at 12:39 am

    If there is “no row at all for the uid”, and you JOIN like you do, you get no row as result. Use LEFT [OUTER] JOIN instead:

    SELECT u.uid, u.fname, u.lname
    FROM   u 
    LEFT   JOIN u_org o ON u.uid = o.uid 
    LEFT   JOIN login l ON u.uid = l.uid 
    WHERE (o.orgid = 2 OR o.orgid IS NULL)
    AND    l.access IS DISTINCT FROM 4;
    

    Also, you need the parenthesis I added because of operator precedence. (AND binds before OR).

    I use IS DISTINCT FROM instead of != in the last WHERE condition because, again, login.access might be NULL, which would not qualify.

    However, since you only seem to be interested in columns from table u to begin with, this alternative query would be more elegant:

    SELECT u.uid, u.fname, u.lname
    FROM   u
    WHERE (u.uid IS NULL OR EXISTS (
       SELECT 1
       FROM   u_org o
       WHERE  o.uid = u.uid
       AND    o.orgid = 2
       ))
    AND NOT EXISTS (
       SELECT 1
       FROM   login l
       WHERE  l.uid = u.uid
       AND    l.access = 4
       );
    

    This alternative has the additional advantage, that you always get one row from u, even if there are multiple rows in u_org or login.

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

Sidebar

Related Questions

I want to get data using CURL but I have a problem. When I
Now I find ploblem again. I want get data in db to listview. but
I want to get data from Postgres. There is a column in type timestamp
I want get data in db to listview. but it have error I cannot
Hi there i want to get data from the below combo box in cakephp
Newbie question: I want to get data between two rows, say, row number 5
I want to get data from ADXL345 accelerometer,but seems that I incorrectly connect it.
I want to get data through Ajax and fill them into div .content, but
im a new in android,I want get data in db to textview. but it
Basically I want get data I already have accessed from javascript and passing it

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.