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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:15:35+00:00 2026-06-12T17:15:35+00:00

I looked in about 18 other posts on here an most people are asking

  • 0

I looked in about 18 other posts on here an most people are asking how to delete the records not just hide them. So my problem: I have a database with staff members who are associated with locations. Many of the staff members are associated with more than one location. What I want to do is to only display the first location listed in the mysql result and skip over the others. I have the sql query linking the tables together and it works aside from it showing the same information for those staff members that are in those other locations multiple times so example would be like this:

enter image description here

This is the sql statement I have currently

    SELECT staff_tbl.staffID, staff_tbl.firstName, staff_tbl.middleInitial, staff_tbl.lastName,
     location_tbl.locationID, location_tbl.staffID, 
    officelocations_tbl.locationID, officelocations_tbl.officeName, staff_title_tbl.title_ID,
     staff_title_tbl.staff_ID, titles_tbl.titleID, titles_tbl.titleName

    FROM staff_tbl 

    INNER JOIN location_tbl ON location_tbl.staffID = staff_tbl.staffID 
    INNER JOIN officelocations_tbl ON location_tbl.locationID = officelocations_tbl.locationID
    INNER JOIN staff_title_tbl ON staff_title_tbl.staff_ID = staff_tbl.staffID 
    INNER JOIN titles_tbl ON staff_title_tbl.title_ID = titles_tbl.titleID 

and my php is

      <?php do { ?>
<tr>
  <td><?php echo $row_rs_Staff_Info['firstName']; ?>&nbsp; <?php echo $row_rs_Staff_Info['lastName']; ?></td>
  <td><?php echo $row_rs_Staff_Info['titleName']; ?>&nbsp; </td>
  <td><?php echo $row_rs_Staff_Info['officeName']; ?>&nbsp; </td>

</tr>
<?php } while ($row_mysqlResult = mysql_fetch_assoc($rs_mysqlResult)); ?>

What I would like to know is there a way using php to select only the first entry listed for each person and display that and just skip over the other two. I was thinking it could be done by possibly adding the staffID’s to an array and if they are in there to skip over the next one listed in the staff_title_tbl but wasn’t quite sure how to write it that way. Any help would be great thank you 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-12T17:15:36+00:00Added an answer on June 12, 2026 at 5:15 pm

    You can use a sub-query on the location_tbl to select only one location per employee

    SELECT staff_tbl.staffID, 
      staff_tbl.firstName, 
      staff_tbl.middleInitial, 
      staff_tbl.lastName,
      location_tbl.locationID, 
      location_tbl.staffID, 
      officelocations_tbl.locationID, 
      officelocations_tbl.officeName, 
      staff_title_tbl.title_ID,
      staff_title_tbl.staff_ID, 
      titles_tbl.titleID, 
      titles_tbl.titleName
    FROM staff_tbl 
    INNER JOIN
    (
      select max(locationID) locationID, staffID
      from location_tbl 
      group by staffID
    ) location_tbl 
      ON location_tbl.staffID = staff_tbl.staffID 
    INNER JOIN officelocations_tbl 
      ON location_tbl.locationID = officelocations_tbl.locationID
    INNER JOIN staff_title_tbl 
      ON staff_title_tbl.staff_ID = staff_tbl.staffID 
    INNER JOIN titles_tbl 
      ON staff_title_tbl.title_ID = titles_tbl.titleID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looked at other posts on SO and they did not solve this issue. I'm
I have seen al most all the other posts about this, but I can't
So, I've looked at some posts about the Specification Pattern here, and haven't found
First of all, I've looked at EVERY other post here, about this (I think)
I have looked at other posts and can't see what I'm doing wrong. I'm
So I have seen other articles here on stack about this and a lot
Little problem about sending PHP array to javascript function, i did homework looked everywhere
I've looked through so many forum posts about this simple piece of code. And
I am a bit lost here as I have not really looked at model
I've looked at a few posts here like this but this doesn't seem to

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.