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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:59:17+00:00 2026-06-03T13:59:17+00:00

I currently have the following SQL statement: SELECT s.first_name, s.last_name, tgs.group_identifier FROM staff s

  • 0

I currently have the following SQL statement:

SELECT s.first_name, s.last_name, tgs.group_identifier
FROM staff s
JOIN staff_training st
ON s.staff_id = st.staff_id
JOIN training_group_staff tgs
ON st.staff_training_id = tgs.staff_training_id
WHERE st.staff_course_id = '164'

training_group_staff only contains the staff_training_id and training_group_id

This statement works as expected and returns all staff names attending course 164 AND have been placed into a group (identified with the group_identifier field).

What I am attempting to do is display all users on training course 164 and if no group selected (there won’t be a row for the specific staff_training_id in training_group_staff) then return null for that column.

Visual Example

Current Statement Returns:

first_name  |  last_name  |  group_identifier
 Jim        |   Jones     |   3
 Harry      |   Jones     |   6

What I am attempting to return is:

first_name  |  last_name  |  group_identifier
 Jim        |   Jones     |   3
 Harriet    |   Smith     |   NULL   // No row in training_group_staff
 Harry      |   Jones     |   6

I have tried several joins, however seem to return the same results – is the desired output possible in one query?

  • 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-03T13:59:20+00:00Added an answer on June 3, 2026 at 1:59 pm

    Try with LEFT JOIN. Should be what you’re after.

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

Sidebar

Related Questions

I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have the following SQL statement: SELECT r.Result AS Resuly, COUNT(f.fieldID) AS [Count] FROM
I have the following SQL statement: SELECT 420, DueDate, ISNULL(Amount, 0) FROM Payments WHERE
I currently have the following MySQL statement to replace the HTML entity for a
I currently have the following js code function clearMulti(option) { var i; var select
Does anyone have an elegant sql statement to delete duplicate records from a table,
I have the following query: SELECT * from foo where timestamp = (select max(timestamp)
Framework: Rails 2.3.8 Database; PostgreSQL I currently have the following SQL statements (generated by
Can anyone please point out what is wrong with the following SQL statement: SELECT
I currently have the following table definition: <table border=1 cellspacing=0 bordercolor=#CEDFEF cellpadding=1> I am

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.