Link to home
Start Free TrialLog in
Avatar of amandajdarlow
amandajdarlow

asked on

SQL Query to mimic MS Access First

Looking at the attaced screenshot can anyone suggest how I can create a SQL Server stored procedure or view which picks out the record with the lowest TagCategorySortId(last column) for each SNT SessionNotesId?

I am no SQL Server guru and I would like to know the 'correct' and 'best' way to do this.

Doc1.docx
Avatar of Zberteoc
Zberteoc
Flag of Canada image

SELECT  TOP 1 * from ... WHERE SessionNotesId=<some_id> ORDER BY TagCategorySortId

However I noticed that you have 2 rows with SessionNotesId=45803 and TagCategorySortId=1. Which one you choose?
Avatar of amandajdarlow
amandajdarlow

ASKER

I need to be able to select all the first records at the same time rather than by SessionNotesId.

In this case " However I noticed that you have 2 rows with SessionNotesId=45803 and TagCategorySortId=1. Which one you choose?  "I am happy to simply select the first or both, it doesn't matter for now.
Can you copy the select statement from the picture in text and post it here? I need to work on it.
SELECT        dbo.tblSessionNoteTags.SNTSessionNotesId, dbo.tblTag.TagId, dbo.tblTagCategory.TagCategorySort
FROM            dbo.tblSessionNoteTags INNER JOIN
                         dbo.tblTag ON dbo.tblSessionNoteTags.SNTTagId = dbo.tblTag.TagId INNER JOIN
                         dbo.tblTagCategory ON dbo.tblTag.TagCategoryID = dbo.tblTagCategory.TagCategoryId
WHERE        (dbo.tblTagCategory.TagCategorySort IS NOT NULL)
ORDER BY dbo.tblSessionNoteTags.SNTSessionNotesId, dbo.tblTagCategory.TagCategorySort
ASKER CERTIFIED SOLUTION
Avatar of Zberteoc
Zberteoc
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brilliant works perfectly.  Thank you very  much.  I shall study the technique later.