Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:07:21+00:00 2026-05-26T13:07:21+00:00

I need some help converting an SQL query into relational algebra. Here is the

  • 0

I need some help converting an SQL query into relational algebra.

Here is the SQL query:

SELECT * FROM Customer, Appointment
WHERE Appointment.CustomerCode = Customer.CustomerCode
    AND Appointment.ServerCode IN
    (
        SELECT ServerCode FROM Appointment WHERE CustomerCode = '102'
    )
;

I’m stuck because of the IN subquery in the above example.

Can anyone demonstrate for me how to express this SQL query in relational algebra?

Many thanks.

EDIT: Here is my proposed solution in relational algebra. Is this correct? Does it reproduce the SQL query?

Scodes ← ΠServerCode(σCustomerCode=’102′(Appointment))

Ccodes ← ΠCustomerCode(Appointment ⋉ Scodes)

Result ← (Customer ⋉ Ccodes)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:07:21+00:00Added an answer on May 26, 2026 at 1:07 pm

    Your SQL code will result in duplicate columns for CustomerCode and the use of SELECT [ALL] is likely to result in duplicate rows. Because the result is not a relation, it cannot be expressed in relational algebra.

    These problems are easily fixed in SQL:

    SELECT DISTINCT * 
      FROM Customer NATURAL JOIN Appointment
     WHERE Appointment.ServerCode IN
        (
            SELECT ServerCode FROM Appointment WHERE CustomerCode = '102'
        )
    ;
    

    You didn’t specify which relational algebra you are intereted in. Date and Darwen proposed an algebra named A, specified an A language named D, and designed a D language named Tutorial D.

    Tutorial D uses operators JOIN for natural join, WHERE for restriction and MATCHING for semijoin, The slight complication is the comparison in SQL:

    CustomerCode = '102'

    The comparison of a CustomerCode value to a CHAR value in SQL is possible because of implicit coercion. Tutorial D is stricter — type safe, if you will — requiring you to overload the equality operator or, more practically, define a selector operator for CHAR, which would typically have the same name as the type.

    Therefore, the above (revised) SQL may be written in Tutorial D as:

    ( Customer JOIN Appointment ) 
       MATCHING ( ( Appointment WHERE CustomerCode = CustomerCode ( '102' ) ) { ServerCode } )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help converting the SQL found below to an equivalent LINQ statement
I need some help in converting my script from using mysql to mysqli I
I just need some help to finish turning this SQL : SELECT us.name, pt.task,
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need some help from the shell-script gurus out there. I have a .txt
I need a little help converting some VB.NET code to C#. I have tried
I often need to execute custom sql queries in django, and manually converting query
I need some help with a program for converting Fahrenheit to Celsius in C.
I wanted help on a simple issue -- converting some ActionScript 2 into AS3.
I need some help converting a java byte array to a 7-Bit ASCII string.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.