how to use distinct in ms access

后端 未结 3 1371
傲寒
傲寒 2020-12-19 05:22

I have two tables. Task and Categories.

\"Task

3条回答
  •  一整个雨季
    2020-12-19 05:59

    Using SELECT DISTINCT will work for you, but a better solution here would be to change your database design.

    Duplicate records may lead to inconsistent data. For example, imagine having two different status in different records with the same TaskID. Which one would be right?

    A better design would include something like a Task table, a Contact table and an Assignment table, as follows (the fields in brackets are the PK):

    Tasks: [TaskID], TaskPriority, Subject, Status, DueDate, Completed, StartDate, Owner, CategoryID, ContactID, ...

    Contact: [ID], Name, Surname, Address, PhoneNumber, ...

    Assignment: [TaskID, ContactID]

    Then, you can retrieve the Tasks with a simple SELECT from the Tasks tables. And whenever you need to know the contacts assigned to a Tasks, you would do so using the JOIN clause, like this

    SELECT T.*, C.*
    FROM TaskID as T 
      INNER JOIN Assignment as A
        ON T.TaskID = A.TaskID
      INNER JOIN Contac as C
        ON A.ContactID = C.ID
    

    Or similar. You can filter, sort or group the results using all of SQL's query power.

提交回复
热议问题