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

  • SEARCH
  • Home
  • 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 7057533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:59:51+00:00 2026-05-28T03:59:51+00:00

So I have a Databases exam in the coming weeks, and as usual I

  • 0

So I have a Databases exam in the coming weeks, and as usual I decided to go over the past papers to see how the question might be. Everything went along fine until I came across this question.

Write a SQL construct for the following query: Which forests are found
in the same geographical region (fo_loc) and are owned by the same
company. The output should have the following structure: Larger Forest
name, Smaller Forest Name, and Company Name. Try to avoid printing the
same forest names pairs more than once.

This is the schema relevant to the question:

TABLE: FOREST

Fo_name character(10) P.K.
Fo_Size Integer
Fo_loc Character(10)
Fo_Comp Character(10))

With my limited knowledge of SQL I do not think this question can be solved declaratively, so I tried also PL/SQL (or rather plpgsql) and I was getting closer and closer to the solution, but it soon dawned on me that I was using many commands we did not cover in class not to mention the solution was getting far from what one would expect out of a 3 mark question.

And so I decided to write here… what is it that I’m missing? Any help would be greatly appreciated.

Thanks

  • 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-28T03:59:52+00:00Added an answer on May 28, 2026 at 3:59 am

    Just a self join should work:

    SELECT a.Fo_Name as 'Larger', 
           b.Fo_Name as 'Smaller',
           a.fo_Comp
    FROM Forest a
    INNER JOIN Forest b
       ON a.fo_Comp= b.fo_Comp
       AND a.fo_loc = b.fo_loc
       AND a.fo_name <> b.fo_name
    WHERE a.fo_size > b.fo_size
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is really hard question. I have an exam. And questions will be like
I have databases with different collations. I want to be able to script out
In Mongo my understanding is that you can have databases and collections. I'm working
We have 18 databases that should have identical schemas, but don't. In certain scenarios,
I have several databases where the transaction log (.LDF) is many times larger than
I have two databases, one is an MS Access file, the other is a
I have 4 databases with similar schema's, and I'm trying to create a query
I have 2 databases, and I want to transport an existing table containing a
I have a databases table with ~50K rows in it, each row represents a
I have some databases that have four files each; one for PRIMARY, IDX, IMAGE,

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.