MSSQL DISTINCT multiple fields throws up odd results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #16
    Originally posted by ukchat
    yes----ish.. or a less there is a different filename for the workbook.

    Trust me i can understand your difficulty in understanding this as i've had to go through the same process for over 200 workbooks.

    the structure is totaly unlogical but unfortunatly i'm not the one that writes the workbooks, so i've had to just put up with it get it in database and now im trying to do this which i thought would be simple as im sure i can do this in MySQL by simply using unique(filename ) then it would only select reccords with a unique filename but MSSQL is being a swine and saying everything has to be distinct rather than just 1 value.

    regards
    Liam
    >>>im sure i can do this in MySQL by simply using unique(filename ) then it would only select reccords with a unique filename

    But again if you select ID in your query, it would give you all the records in which the filename and workbook will repeat. If you DO NOT select the ID column then you will get the UNIQUE filenames for each workbook as I did earlier using GROUP BY workbook clause.

    Comment

    • ukchat
      New Member
      • Sep 2006
      • 15

      #17
      Originally posted by amitpatel66
      >>>im sure i can do this in MySQL by simply using unique(filename ) then it would only select reccords with a unique filename

      But again if you select ID in your query, it would give you all the records in which the filename and workbook will repeat. If you DO NOT select the ID column then you will get the UNIQUE filenames for each workbook as I did earlier using GROUP BY workbook clause.

      The thing is i need the ID to pull out the correct workbook. I suppose i could work arround it by running a query to select IF FROM table WHERE filename = 'filenamevalue'

      was just hopinf for somthing all in 1 but will give this a blast.

      EDIT: Actually that wont work as when using DISTINCT and putting workbook as a field it select distinct workbook too! which means i cant have multiple workbooks returned where there are more than 1 file.


      regards
      Liam

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #18
        Originally posted by ukchat
        The thing is i need the ID to pull out the correct workbook. I suppose i could work arround it by running a query to select IF FROM table WHERE filename = 'filenamevalue'

        was just hopinf for somthing all in 1 but will give this a blast.

        regards
        Liam
        Ok. So from Front end, you will be passing ID as input parameter value is it? If yes, then using ID value, its simple to get the corresponding filename.

        Could you post what are the columns you need in your select query from the below:

        1. Filename,workbo ok,ID? -- If yes, then MAX(ID) to get a single record for each work book?

        2. Filename,workbo ok -- Need to take MAX(filename) group by workbook which will give distinct records

        3. Filename - DISTINCT filename fomr corresponding table

        And it would be great if you can provide the way you want your output to be (sample output) for reference?

        Comment

        Working...