Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013
    Posts
    3

    Unanswered: Relational Algebra - Find Duplicates

    What operation would be used to find duplicate entries in just one field for one table in a database? So like how would you find all of the entries with a surname that is repeated?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    select surname
    from some_table
    group by surname
    having count(*) > 1
    You should really read a good SQL tutorial - this is basic SQL knowledge.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  3. #3
    Join Date
    Oct 2013
    Posts
    3
    Quote Originally Posted by shammat View Post
    Code:
    select surname
    from some_table
    group by surname
    having count(*) > 1
    You should really read a good SQL tutorial - this is basic SQL knowledge.
    Thank you for the help, but I am not looking for the SQL syntax. I have general knowledge of SQL but this is for a university coursework to do with relational algebra. I have to use relational algebra only so things like project, natjoin, equijoin etc.

    Here is the question in full (I don't want the answer to the question, I just want some help on what operation to use because I haven't picked this up in a lecture and have went through the slides several times):

    3. Find the age and address of the patients that have had at least two operations with broken leg.

    The part I'm stumped on is finding patients that have two entries of operation type "broken leg" in the Completed_Operations table.

  4. #4
    Join Date
    Dec 2013
    Posts
    43
    Provided Answers: 1
    Pokie,

    First make a query to join the Patients table to the Completed_Operations table.
    You'll group by Patient, OperationType.
    Use the Having clause to limit results to "broken leg" and at least two entries.

    Then join your Patients table to the query to pick up the patient's age/address.

    You'll have to supply the "relational algebra" words, but that's what you have to do.

    hth,
    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •