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

The Archive Base Latest Questions

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

Basically I have a table which is used to hold employee work wear details.

  • 0

Basically I have a table which is used to hold employee work wear details. It is formed of the columns:

EmployeeID, CostCentre, AssociateLevel, IssueDate, TrouserSize, TrouserLength, TopSize & ShoeSize. 

An employee can be assigned a pair of trousers, a top and shoes at the same time or only one or two pieces of clothing. As we all know peoples sizes and employee levels can change which is why I need help really. Different types of employees (associatelevels) require different colours of clothing but you can ignore this part. Everytime an employee receives an item of clothing a new row will be inserted into the table with an input date. I need to be able to select the most recent clothes size for each item of clothing for each employee.

It is not necessary for all the columns to hold values because an employee could receive trousers or poloshirts at different times in the year.

So for example if employee ‘54664LSS’ was given a pair of ‘XL’ trousers and a ‘L’ top on 24/03/11 but then received a ‘M’ top on 26/05/10. The input of these items would be help on two different rows obviously. So if I wanted to select the most recent clothing for each clothes category. Then the values of the ‘M’ sized top and the ‘L’ sized trousers would need to be returned.

Any help would be greatly appreciated as I’m pretty stuck :(. Thanks.

  • 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-14T07:51:49+00:00Added an answer on May 14, 2026 at 7:51 am

    It’s always easier to answer if you can give a schema definition and some sample data, and the expected output, rather than a commentary. I’ve attempted a schema definition, haven’t got any sample data, and think that this answer gives what you want:

    /*create table Clothing (
     EmployeeID int not null,
     CostCentre varchar(10) not null,
     AssociateLevel int not null,
     IssueDate datetime not null,
     TrouserSize int null,
     TrouserLength int null,
     TopSize varchar(4) null,
     ShoeSize varchar(10) null
    )*/
    go
    with Trousers as (
     select
      EmployeeID,
      CostCentre,
      AssociateLevel,
      IssueDate,
      TrouserSize,
      TrouserLength,
      RANK() OVER (PARTITION BY EmployeeID ORDER BY IssueDate Desc) as RowNum
     from
      Clothing
     where
      TrouserSize is not null
    ), Tops as (
     select
      EmployeeID,
      CostCentre,
      AssociateLevel,
      IssueDate,
      TopSize,
      RANK() OVER (PARTITION BY EmployeeID ORDER BY IssueDate Desc) as RowNum
     from
      Clothing
     where
      TopSize is not null
    ), Shoes as (
     select
      EmployeeID,
      CostCentre,
      AssociateLevel,
      IssueDate,
      ShoeSize,
      RANK() OVER (PARTITION BY EmployeeID ORDER BY IssueDate Desc) as RowNum
     from
      Clothing
     where
      ShoeSize is not null
    )
    select
      COALESCE(tr.EmployeeID,tops.EmployeeID,sh.EmployeeID) as EmployeeID,
      tr.CostCentre,
      tr.AssociateLevel,
      tr.IssueDate,
      tr.TrouserSize,
      tr.TrouserLength,
      tops.CostCentre,
      tops.AssociateLevel,
      tops.IssueDate,
      tops.TopSize,
      sh.CostCentre,
      sh.AssociateLevel,
      sh.IssueDate,
      sh.ShoeSize
    from
     Trousers tr
      full outer join
     Tops
      on
       tr.EmployeeID = Tops.EmployeeID
      full outer join
     Shoes sh
      on
       tr.EmployeeID = sh.EmployeeID and
       Tops.EmployeeID = sh.EmployeeID
    where
     (tr.RowNum is null or tr.RowNUm = 1) and
     (Tops.RowNum is null or Tops.RowNUm = 1) and
     (sh.RowNum is null or sh.RowNum = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like the following which is basically used to give a
I have built a table which is basically done by HorizontalScrollView inside a ScrollView
I have a mysql table with three columns: username, location, timestamp. This is basically
Basically I have a table that is being used to display data from an
I've a field of type char(1) in my MySQL table which basically can have
Basically, I have a table which contains a few properties for a company. This
So I have this user-defined table type parameter, which is used in my scalar
So basically I have a table - ID | from | To ----------------- 1
If I were to select a row from a table I basically have two
Basically I have a database with two tables, that is, Updates table and Images

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.