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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:47:35+00:00 2026-06-13T23:47:35+00:00

Looking at the following SQL fiddle: http://sqlfiddle.com/#!2/962496/1 How could one select all orders from

  • 0

Looking at the following SQL fiddle: http://sqlfiddle.com/#!2/962496/1

How could one select all orders from user b@b.cn with userpk = 2 and reg = 1 but only
the two most recent orders from a@a.cn with userpk = 1 and reg = 0. So the query will show 3 orders for userpk = 2 but only 2 orders (not the earliest order 2012-01-01 from userpk = 1

So the condition would be reg, if reg = 0 then ignore first order

  • 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-13T23:47:36+00:00Added an answer on June 13, 2026 at 11:47 pm

    I think this will give you the result that you want:

    select *
    from users u
    left join another a
      on u.userpk = a.uPK
    where
    (
      u.userpk = 2
      and u.reg = 1
    )
    or
    (
      u.userpk = 1
      and u.reg = 0
      and a.odate not in (select min(odate)
                          from another a1
                          where u.userpk = a1.uPK)
    ) 
    

    See SQL Fiddle with Demo

    A version not specific to single users (if you have more than 2 users):

    select *
    from users u
    left join another a
      on u.userpk = a.uPK
    where
    (
       u.reg = 1
    )
    or
    (
      u.reg = 0
      and a.odate not in (select min(odate)
                          from another a1
                          where u.userpk = a1.uPK)
    ) 
    

    See SQL Fiddle with Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to convert the following SQL into Linq2SQL. select isnull(max(Id),0) from tbl Even
I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
I would like to generate the following sql from ICriteria select c.Id, sum(c.Amount) Amount,
I have the following SQL: SELECT `table1`.`value`, `table2`.* FROM `table2` INNER JOIN `table1` ON
I have the following minimal schema in Oracle: http://sqlfiddle.com/#!4/c1ed0/14 The queries I have run
I am looking for equivalent of the following for Entity SQL. from row in
I'm looking to move the following code away from ActiveRecord to pure SQL for
I am looking for the SQL syntax to use HAVING in the following statement:
I'm looking for an SQL client app that can display subdatasheets like the following:
I'm looking for the following solution in PHP. Whenever a user clicks on a

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.