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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:05:21+00:00 2026-05-22T20:05:21+00:00

I have two very simple tables in Oracle 9G: Customer userid | firstName |

  • 0

I have two very simple tables in Oracle 9G:

Customer

userid | firstName | lastName | email 
-------+-----------+----------+---------------------
  1      user1       User1      user1@mail.in
  2      user2       User2      user2@mail.in

Order

orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+-------
1          1          0         12/12/2009    1
2          1          1         13/12/2009    2
3          1          1         14/12/2009    3
4          2          0         12/12/2009    4
5          2          1         16/12/2009    2
6          1          0         14/12/2009    5
7          2          1         17/12/2009    4
8          2          0         10/12/2010    2

I want to select all users which have orders of type 0

select *    
from Customer c 
inner join Order o on c.userid = o.userid 
where o.orderType = '0'

The result is:

orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+--------
1          1          0         12/12/2009    1
4          2          0         12/12/2009    4
6          1          0         14/12/2009    5
8          2          0         10/12/2010    2

Now I need to modify this query to bring only last purchase date for each user id and get the result like this:

orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+--------
6          1          0         14/12/2009    5
8          2          0         10/12/2010    2

How should I modify my query to get this result?

  • 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-22T20:05:22+00:00Added an answer on May 22, 2026 at 8:05 pm
    SELECT * 
    FROM order o
    WHERE o.orderType ='0'
      AND o.order_date = 
          ( SELECT MAX(o2.order_date)
            FROM order o2
            WHERE o2.userid = o.userid
              AND o2.orderType = '0'
          )
    

    or

    SELECT o.* 
    FROM order o
      JOIN
        ( SELECT userid
               , MAX(order_date) AS lastPurchaseDate
          FROM order 
          WHERE o.orderType ='0'
          GROUP BY userid
        ) AS grp
        ON grp.userid = o.userid
        AND grp.lastPurchaseDate = o.order_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple access db with two tables linked by a 1-M
I have very simple form along with two database tables. In this form is
I have a very simple application with two tables, ParentTable and ChildrenTable . Each
I have two very simple tables. Product and ProductCategory (ProductCategory is like a 'lookup'
I have a very simple table with two columns, but has 4.5M rows. CREATE
I have two very simple, identical UITableViews in my app that are populated with
The situation is very simple, I have two panel. In the event of OnMouseOver
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I'm noticing strange behavior. I have merchant and order tables and doing two selects
I have a simple query that relies on two full-text indexed tables, but it

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.