# Querying due cards with SQLite

**URL:** <https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468>\
**Category:** Development\
**Created:** [December 1, 2021, 2:43pm UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468 "2021-12-01T14:43:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![imnoone](https://avatars.discourse-cdn.com/v4/letter/i/7cd45c/32.png) [@imnoone](https://forums.ankiweb.net/u/imnoone)\
**Post date:** [December 1, 2021, 2:43pm UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/1 "2021-12-01T14:43:34Z")

</div>

Hey, you. Can you help with my SQL problem?  
I am able to query new cards by opening my database file with SQL browser. However, I am having a hard time querying the due cards. Is there a way to return only the cards due today? I am able to return (I believe) all due cards. I can rephrase my question in case you find it confusing. I am using the following query  
`SELECT DISTINCT id FROM cards WHERE queue = 2;`  
It’s returning all due cards of all days. Do you happen to know how can I solve this?

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [December 1, 2021, 3:31pm UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/2 "2021-12-01T15:31:08Z")

</div>

I suggest you look at how Anki queries due cards: [anki/sqlwriter.rs at main · ankitects/anki · GitHub](https://github.com/ankitects/anki/blob/main/rslib/src/search/sqlwriter.rs#L317-L329)  
As you can see, it depends on the queue (review, learn, …) and you have to specify the appropriate time.

---

<div class="post-metadata">

**Author:** ![imnoone](https://avatars.discourse-cdn.com/v4/letter/i/7cd45c/32.png) [@imnoone](https://forums.ankiweb.net/u/imnoone)\
**Post date:** [December 1, 2021, 7:41pm UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/3 "2021-12-01T19:41:58Z")

</div>

I’m finding it very difficult to implement on my code because I need to run it ouside anki (because I don’t want to depend on wheter or not the software is running) - so I have no idea how to get those variable or even if it’s possible to do this.

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [December 1, 2021, 8:14pm UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/4 "2021-12-01T20:14:32Z")

</div>

Sure, it’s possible, but quite involved and not achievable with SQL alone.

---

<div class="post-metadata">

**Author:** ![imnoone](https://avatars.discourse-cdn.com/v4/letter/i/7cd45c/32.png) [@imnoone](https://forums.ankiweb.net/u/imnoone)\
**Post date:** [December 2, 2021, 6:47am UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/5 "2021-12-02T06:47:04Z")

</div>

So no way of doing it with SQL only? Because I don’t need the actual cards, just the card count of the day (literally just the number).

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [December 2, 2021, 7:47am UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/6 "2021-12-02T07:47:16Z")

</div>

[https://addon-docs.ankiweb.net/command-line-use.html](https://addon-docs.ankiweb.net/command-line-use.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 3:16am UTC](https://forums.ankiweb.net/t/querying-due-cards-with-sqlite/15468/7 "2023-05-01T03:16:42Z")

</div>


