• 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
Re: A bit of SQL help and logic correction, perhaps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A bit of SQL help and logic correction, perhaps


  • Subject: Re: A bit of SQL help and logic correction, perhaps
  • From: Brent Shank <email@hidden>
  • Date: Fri, 10 Jan 2003 11:15:48 -0800

First question: Why are you using raw SQL rather than EOQualifier and EOSortOrderings?

Brent

On Thursday, January 9, 2003, at 05:53 PM, Reid Bundonis wrote:

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.
_______________________________________________
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.

References: 
 >A bit of SQL help and logic correction, perhaps (From: Reid Bundonis <email@hidden>)

  • Prev by Date: ClassCastException...
  • Next by Date: saving / addObjectToBothSidesOfRelationshipWithKey
  • Previous by thread: A bit of SQL help and logic correction, perhaps
  • Next by thread: Re: A bit of SQL help and logic correction, perhaps
  • Index(es):
    • Date
    • Thread