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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:00:36+00:00 2026-05-25T15:00:36+00:00

I’m writing an application for android and have a fairly simple SQLite3 database (see

  • 0

I’m writing an application for android and have a fairly simple SQLite3 database (see pic), but I’m having a lot of trouble with a specific query.

Here’s (a part of) the database. Note: there’s a one-to-many relationship here. A player can have many events but only 1 player for each event.

Table model

I want to have a list of all the players, but I need to order this list of all players by whether they have an event that has it’s Diagnosed attribute set to false or not(i.e. All players with an “Undiagnosed” event go at the top, all other players come after). If they have more than one “Undiagnosed” event than the newest one is used.

That’s the trickiest part of the query. After that the players with the “Undiagnosed” events need to be ordered by their ‘Magnitude’ attribute (int), and the other players (any player that doesn’t have any “undiagnosed” events) need to be ordered by their last name.

Here’s an example of the list I need:

  • Player <–1 Undiagnosed event (100 magnitude)
  • Player <–2 Undiagnosed events (Newest one 75 magnitude)
  • Player <–1 Undiagnosed event (50 magnitude)
  • Player <– No Undiagnosed Events (Name: Johnny Appleseed)
  • Player <– No Undiagnosed Events (Name: Jim Zebra)

The only way I can think of doing this is by using 2 separate queries (one for “Undiagnosed” players and another for everyone else) but I don’t think that’s the best way of doing this.

Thanks in advance!

Edit

Ok so here’s the query that’s mostly working now.

select player.PlayerID, player.fname, player.lname, stats.diagcount, topmag.magnitude 
from player left outer join (
select playerid, MIN(diagnosed) as diagcount
from events group by playerid
)as stats on player.playerid = stats.playerid
left outer join (
select playerid,max(magnitude) as magnitude
from events group by playerid
)as topmag on player.playerid=topmag.playerid
order by CASE WHEN stats.diagcount Is NULL Then 1 Else 0 End,stats.diagcount,topmag.magnitude,lname;

Only problem now is that players at the bottom of the list (Players without any diagnosed events) are being sorted by their most recent event magnitude and not by last name.

  • 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-25T15:00:37+00:00Added an answer on May 25, 2026 at 3:00 pm

    something like:

    select player.fname, player.lname, stats.diagcount, topmag.highest
    from player left outer join (
         select playerid, count(time) as diagcount
         from events group by playerid
    )as stats on player.playerid = stats.playerid
    left outer join (
       select playerid,max(magnitude) as highest
        from events group by playerid
    )as topmag on player.playerid=topmag.playerid
    order by stats.diagcount,topmag.highest,lname
    

    dunno whats possible in sqllite but i think something like that might work, if you get errors post them and I will see what I can do

    If you want to eliminate sorting by magnitude on player whos events are diagnosed then you could eliminate them from the sub queries..

    select player.fname, player.lname, stats.diagcount, topmag.highest
    from player left outer join (
         select playerid, count(time) as diagcount
         from events 
         where diagnosed = 0
         group by playerid
    )as stats on player.playerid = stats.playerid
    left outer join (
       select playerid,max(magnitude) as highest
        from events 
        where diagnosed = 0
        group by playerid
    )as topmag on player.playerid=topmag.playerid
    order by stats.diagcount,topmag.highest,lname
    

    sorry I might have the diagnosed thing the wrong way round (as in maybe it should be diagnosed = 1)

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.