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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:21:51+00:00 2026-05-29T07:21:51+00:00

I have a SQL query and here it is the part I’m stuck on.

  • 0

I have a SQL query and here it is the part I’m stuck on.

$query = "SELECT DISTINCT user.firstname, user.lastname, user.userid FROM user, staff WHERE user.type = 'Staff' AND staff.userid!= user.userid";

For some reason, it only prints out the part where users are staff but the != is not working, where as if I remove the ! and only have staff.user_id = user.user_id it works and prints out all users that are in both of those tables?

Can someone please explain why is this is happen and have a solution.

EDIT

TABLE USER                       TABLE STAFF
ID - NAME - TYPE                ID   -     NUMBER
1  - A    - Staff               1    -      11111
2  - B    - Staff               2    -      22222
3  - C    - Customer
4  - D    - Customer
5  - E    - Staff
6  - F    - Staff

How would I find the users id 5 and 6?

  • 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-29T07:21:52+00:00Added an answer on May 29, 2026 at 7:21 am

    Try <> instead of !=.

    Edited answer for the edited question:

    SELECT user.firstname, user.lastname, user.userid 
    FROM user LEFT JOIN staff ON user.userid=staff.userid 
    WHERE user.type = 'Staff' AND staff.userid IS NULL ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have this JDBC SQL query: select * from table where TX_DATE = {d
I have a large T-SQL query (I only put a part here because I
Have following String built SQL query: StringBuilder querySelect = new StringBuilder(select * from messages
So I have following as part of my query SELECT * FROM $table WHERE
I have the following sql query SELECT * FROM jos_jcalpro_events AS e LEFT JOIN
We have a SQL query that pulls a large number of fields from many
I have a complex SQL Query, that needs to be filtered further. Part of
I have got a SQL command like the following : SELECT * FROM temp1

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.