简体   繁体   中英

Core data fetch request with GROUP BY

I have a table in my application which consists of some names and phone numbers and orderIDs and dates (4 columns). I want to get an array of all distinct phone numbers (Note that someone with a phone number may have several orderIDs).

Test case: suppose that this is the current records of my table.

Name phoneNumber orderID date John 1234 101 2014-12-12 Susan 9876 102 2014-12-08 John 1234 103 2014-12-17

I want an array of distinct phone numbers only, something like: {1234, 9876} How can I perform such a fetch in core data?

Any help would be much appreciated. Thank you.

PS: As I knew in SQL I could do something like:

SELECT phoneNumber FROM orders GROUP BY phoneNumber

You can use Distinct Keyword. so your query will become

SELECT DISTINCT phoneNumber FROM orders

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM