Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

Select field corresponding to min sequence number

I have two tables to query. The first contains a log of complaints, the second contains note records for each complaint, where there can be multiple note records for each complaint with the first line in the note being assigned a sequence value of 1, the second a sequence value of 2, etc. Sometimes there will be no note at all.

What is the best way to set up the below query so that I select the note corresponding to sequence 1 for each complaint?

SELECT table1.complaint_id, table1.itemnumber, table1.quantity, ???table2.FIRST_NOTE_IN_SEQUENCE??? FROM table1 LEFT JOIN table2 ON table1.complaint_id = table2.complaint_id

As a bonus, anybody know a way to set this query up to show all note records for each complaint without causing repetitions of complaint id, item number and quantity?

question from:https://stackoverflow.com/questions/65902736/select-field-corresponding-to-min-sequence-number

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...