Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Represent a subquery in relational algebra

How do I represent a subquery in relation algebra? Do I put the new select under the previous select condition?

SELECT number
FROM collection
WHERE number = (SELECT anotherNumber FROM anotherStack);
like image 654
AnEventHorizon Avatar asked Oct 03 '10 17:10

AnEventHorizon


People also ask

How do you write a subquery in relational algebra?

Then you have to convert the sub-query first into relational algebra. To do this for the sub-query given above: PI[some-column-from-sub-query]( SIGMA[extra-where-clause-if-needed ^ some-column = some-column-from-sub-query ](RO[T1](R1) x RO[T2](R2) x ...

What is a subquery with example?

In SQL, it's possible to place a SQL query inside another query known as subquery. For example, SELECT * FROM Customers WHERE age = ( SELECT MIN(age) FROM Customers ); Run Code. In a subquery, the outer query's result is dependent on the result-set of the inner subquery.

How do you write a subquery?

Subquery must be enclosed in parentheses. Subqueries are on the right side of the comparison operator. ORDER BY command cannot be used in a Subquery. GROUPBY command can be used to perform same function as ORDER BY command.

How would you best describe a subquery?

A subquery is a query that is nested inside a SELECT , INSERT , UPDATE , or DELETE statement, or inside another subquery.


1 Answers

You would just rewrite that as a join.

I'm not sure how widely used the syntax I learned for Relational Algebra is so in words.

  1. Take a projection of anotherNumber from anotherStack
  2. Rename anotherNumber from the result of step 1 as number
  3. Natural Join the result of step 2 onto collection
  4. Take a final projection of number from the result of step 3
like image 121
Martin Smith Avatar answered Oct 02 '22 00:10

Martin Smith