How Can Relational Algebra Be Used to Find Diseases With Only One Medication?

  • Thread starter Shaitan00
  • Start date
  • Tags
    Algebra
In summary, to find the diseases for which there is only one medication, we can use the aggregate function COUNT to count the number of medications for each disease and then use the HAVING keyword to select only those with a count of 1. This will give us the desired result of CANCER and HIV in the given example.
  • #1
Shaitan00
18
0
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...
Thanks,
 
Last edited:
Mathematics news on Phys.org
  • #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?

Thanks,
 
  • #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).
 

FAQ: How Can Relational Algebra Be Used to Find Diseases With Only One Medication?

1. What is Relational Algebra of a Query?

Relational Algebra of a Query is a formal query language used to retrieve data from a relational database. It consists of a set of operations that can be applied to relations or tables, such as selection, projection, union, intersection, and join.

2. What are the benefits of using Relational Algebra of a Query?

Using Relational Algebra of a Query allows for a more precise and structured way of querying data from a database. It also allows for standardized operations that can be applied to any relational database, making it easier to learn and use for data analysis.

3. How is Relational Algebra of a Query different from SQL?

Relational Algebra of a Query is a theoretical language used to describe the operations and logic behind querying a database, while SQL (Structured Query Language) is a practical language used to actually execute queries on a database. Relational Algebra of a Query is used as the basis for SQL, but SQL has additional features and syntax that make it more user-friendly.

4. Can Relational Algebra of a Query be used for complex queries?

Yes, Relational Algebra of a Query can be used for both simple and complex queries. It allows for the combination of different operations to create more complex and sophisticated queries, making it a powerful tool for data analysis.

5. Are there any limitations to using Relational Algebra of a Query?

One limitation of Relational Algebra of a Query is that it is not user-friendly, as it is a theoretical language that requires knowledge of set theory and mathematical notation. It also does not have all the features and functions that SQL has, making it less versatile for certain types of queries.

Back
Top