1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Relational Algebra of a Query

  1. Jun 23, 2008 #1
    I am trying to write the RELATIONAL ALGEBRA statement for a query defined as follows:
    "Find the diseases for which there is only one medication"

    I have a table TREATMENT with two attributes, DISEASE & MEDICATION
    TREATMENT (disease, medication)

    This table holds a list of diseases and corresponding medication, of course for each diseases that can potentially be multiple medications, and for some only one. For example assume you have something that resembles the following:

    Disease | Medication
    FLU | med1
    FLU | med2
    CANCER | med3
    HIV | med4
    FLU | med5

    In this case you would expect to get CANCER & HIV (as they only have 1 corresponding medication) whereas FLU would be excluded because it has 3... (etc...)

    Any help would be greatly appreciated...
    Last edited: Jun 23, 2008
  2. jcsd
  3. Jun 23, 2008 #2
    Last edited by a moderator: Apr 23, 2017
  4. Jun 23, 2008 #3
    I was looking at that already - but couldn't figure it out...
    WIth those expressions I can easily determine the COUNT for each but how do I list only the diseases that have a count = 1?

  5. Jun 24, 2008 #4
    SQL uses a HAVING keyword for such cases, which is nothing but a select operation on the result of the aggregation. I believe the only reason to define in SQL a different keyword than WHERE was to distinguish between a select operation after the aggregation (HAVING), as opposed to before (WHERE).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook