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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:12:52+00:00 2026-05-22T02:12:52+00:00

I have two tables like this:- TABLE A ITEM LOCATION CODE A WHS QW123

  • 0

I have two tables like this:-

TABLE A

ITEM    LOCATION    CODE
A       WHS         QW123
B       WHS         QW124
C       WHS         QW125

TABLE B

ATR_NO          ITEM    CODE    ATT_ID  ATT_VALUE
20110101123310  A   QW123   SIZE    24
20110101123310  A   QW123   GRADE   2
20110101123351  B   QW124   SIZE    20
20110101123351  B   QW124   GRADE   3
20110101124042  C   QW125   SIZE    26
20110101124042  C   QW125   GRADE   4
20110101131210  A   QW123   SIZE    26
20110101131210  A   QW123   GRADE   1
20110101144542  C   QW125   SIZE    27
20110101144542  C   QW125   GRADE   1

The expected results using SQL shold look like this:-

RESULT

ITEM    LOCATION    CODE    SIZE    GRADE
A       WHS         QW123   26  1
B       WHS         QW124   20  3
C       WHS         QW125   27  1

How can I achieve that ?

  • 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-22T02:12:53+00:00Added an answer on May 22, 2026 at 2:12 am

    Get the latest ATR_NO for each item, join that with table b twice to get the size and grade:

    select
      a.ITEM, a.LOCATION, a.CODE, SIZE = b1.ATT_VALUE, GRADE = b2.ATT_VALUE
    from
      [TABLE A] a
      inner join (select max(ATR_NO) from [TABLE B] group by ITEM) i on i.ITEM = a.ITEM
      inner join [TABLE B] b1 on b1.ATR_NO = i.ATR_NO and b1.ATT_ID = 'SIZE'
      inner join [TABLE B] b2 on b2.ATR_NO = i.ATR_NO and b2.ATT_ID = 'GRADE'
    order by
      a.ITEM
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You have two hypothetical tables: TABLE 1 [id] [item] [amount] [cost] 1 hat 20
Say that I have two tables like those: Employers (id, name, .... , deptId).
I have two tables A and B. I would like to delete all the
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
I have two tables like the below one in my DB. In the first
I have two temp tables, both populated by TSQL queries. Temp Table A containing
I have two tables having 1 to 1 relationship. One table called Person and
I have two tables that are joined together. A has many B Normally you
I have two tables, Book and Tag , and books are tagged using the
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType

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.