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 8882119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:29:51+00:00 2026-06-14T20:29:51+00:00

I have 3 tables. driver, trip, tripLegs In driver table the columns are E#,

  • 0

I have 3 tables.

driver, trip, tripLegs

In driver table the columns are E#, L#, STATUS.
In trip table the columns are T#, L#, REG#, trip_DATE
In tripLeg table the columns are T#, LEG#, DEPARTURE, DESTINATION

First I tried a sql query which is:

select d.l#, count(tg.leg#) as total_no_of_legs
from driver d left outer join trip t on (d.l# = t.l#)
left outer join tripleg tg on (t.t# = tg.t#)
group by d.l#;

Results i got was:

L#         Total_no_of_legs
-----------------------------
11111        20

and so on.

This is the total number of legs from all T#’s leg#
e.g

T#1 's leg# = 3
T#2's leg# = 10
T#3's leg# = 7

Total = 20 that is why L# 11111 total no of Legs is 20.
But I wanna find out the max leg# of each L# which is 10.
How do I do a query to find out highest number of LEG# group by T#?

Afterwhich, how do I really start to convert this into a PL/SQL statement?

Have been wondering all day and reading up on books. Still couldnt find a solution to it

  • 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-06-14T20:29:53+00:00Added an answer on June 14, 2026 at 8:29 pm

    But I wanna find out the max leg# of each L#

    Maybe I’m missing something, but isn’t that simply:

    select d.l#, 
           max(tg.leg#) as max_leg_nr
    from driver d 
      left outer join trip t on (d.l# = t.l#)
      left outer join tripleg tg on (t.t# = tg.t#)
    group by d.l#
    

    I don’t see the need to put this into a stored procedure.

    To put this into a function that returns the result, you need a pipelined function:

    create type leg_info as object (l# integer, max_leg_nr integer);
    /
    
    create type leg_info_list as table of leg_info
    /
    
    create or replace function get_max_leg_info
      return leg_info_list
      PIPELINED
    as
      r_info leg_info;
    begin
       r_info := leg_info(null, null);
       for p_rec in ( .... here goes the select ... )
       loop
         r_info.l# := p_rec.l#;
         r_info.max_leg_nr := p_rec.max_leg_nr ;
         pipe row(r_row);
       end loop;
       return;
    end;
    /
    

    You can then use this function like this:

    select *
    from table(get_max_leg_info())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables linked by FK, I query on the first table using entity
I have two tables. Table 1: supportstatus clientid company status Table 2: client clientid
I have 2 tables, Driver and Mechanic and in both table they have a
I have two tables: DRIVER(Driver_Id,First name,Last name,...); PARTICIPANT IN CAR ACCIDENT(Participant_Id,Driver_Id-foreign key,responsibility-yes or no,...).
i have tables driver, cars and trailers they are all in relationship. and main
So imagine i have two tables, Car and Driver, with respectively these structure :
I have the following MySQL tables (Simplified) DRIVER (D) ---------- id (PK) name RACE
I have a car table and driver table. Each car can be driven by
I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile
If I have two tables; Drivers keyed by DriverId and Trips with foreign keys

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.