• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
A bit of SQL help and logic correction, perhaps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A bit of SQL help and logic correction, perhaps


  • Subject: A bit of SQL help and logic correction, perhaps
  • From: Reid Bundonis <email@hidden>
  • Date: 09 Jan 03 20:53:22 -0500

Ok, I have a table (LETTER) that contains three columns, NAME, SUBJECT, IS_HIGHLIGHTED. The column, IS_HIGHLIGHTED is a boolean, and is set to 1 if true, otherwise I leave it null.  The application started rather simple.  As main loaded, I would fetch a random set of results and display them in a repetition using a Fetch Specification's raw expression, for example:

SELECT * FROM LETTER WHERE IS_HIGHLIGHTED = 1 ORDER BY RAND() LIMIT 5;

However, now I need to be able to select all of the IS_HIGHLIGHTED = 1 (true) records, and a random set of not highlighted records limited to 5.  The highlighted records must come at the top of the results, and the non highlighted records come beneath it.

Logically, I keep telling myself that this is two trips to the database in two distinct selects since the results are really two different sets.  However, I figured I would throw out the question to the group to see if there is a solution.  I tried to place the order by only on the IS_HIGHLIGHTED IS NULL part like:

SELECT * FROM LETTER WHERE (IS_HIGHLIGHTED = 1) OR  (IS_HIGHLIGHTED IS NULL ORDER BY RAND() LIMIT 5);

Obviously, it was not happy.  I am guessing that I need to do this as two fetches.  I guess I am looking for a simple way out.

Thanks for your help.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: A bit of SQL help and logic correction, perhaps
      • From: Brent Shank <email@hidden>
  • Prev by Date: Re: EOSharedEditingContext and objectsMatchingValues
  • Next by Date: Re: Project Builder Assistant
  • Previous by thread: Re: Project Builder Assistant
  • Next by thread: Re: A bit of SQL help and logic correction, perhaps
  • Index(es):
    • Date
    • Thread