Jump to content

MSSQL DISTINCT multiple fields throws up odd results


shocker-z

Recommended Posts

I.m creating a dynamic query to pull out workbooks from my database the table structure is below.

 

Table: curricworkbooks

Columns: ID, curric, assessment, topic, workbook, filename

 

Example data

[iD]	[curric]	[assessment]	[topic]		[workbook]	[filename]
1	N1/E1.1 	Numeracy E1	Count		1		workbooks/Num Entry 1/Unit 1/04 N1E1.1-3 Worksheets Num.pdf
10	MSS1/E1.6	Numeracy E1	Capacity 	13		workbooks/Num Entry 1/Unit 13/04 MSS1E1.6 Worksheets Num.pdf
100	MSS1/L1.7	Numeracy L1	Conversions	14		workbooks/Numeracy Level 1/wkbk_14 AoN L1 2D 3D & Scale.pdf

 

So my system will output each workbook in a table which works fine. using thsi query

 

SELECT distinct(curricworkbooks.filename),workbook FROM curricworkbooks WHERE assessment = 'Literacy E2' AND workbook IS NOT NULL ORDER BY workbook ASC

 

but i need to also select the ID field from the table, so i thought the query would be somthing like this:

 

SELECT distinct(curricworkbooks.filename),workbook, ID FROM curricworkbooks WHERE assessment = 'Literacy E2' AND workbook IS NOT NULL ORDER BY workbook ASC

 

But when i use that query i get non distinct results. I need the distinct on filename as there can be multiple curriculum reference per each workbook which can relate to the same file (Trust me just beleive me on this on the structure is totaly unlogical but it's data that im unable to change.)

 

All support greatlt appreciated.

 

Posted simular to this yesterday but think the site got restored again.

 

regards

Liam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.