# Prepared Statement Query Returns Duplicate Records but CrateDB Console Query Doesn’t

**URL:** <https://community.cratedb.com/t/prepared-statement-query-returns-duplicate-records-but-cratedb-console-query-doesn-t/1966>\
**Category:** CrateDB\
**Tags:** sql\
**Created:** [January 22, 2025, 2:19pm UTC](https://community.cratedb.com/t/prepared-statement-query-returns-duplicate-records-but-cratedb-console-query-doesn-t/1966 "2025-01-22T14:19:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunil](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@Sunil](https://community.cratedb.com/u/Sunil)\
**Post date:** [January 22, 2025, 2:19pm UTC](https://community.cratedb.com/t/prepared-statement-query-returns-duplicate-records-but-cratedb-console-query-doesn-t/1966/1 "2025-01-22T14:19:35Z")

</div>

Hello,

When we execute a query using a prepared statement, it returns duplicate records, while running the same query directly on the CrateDB console gives the correct results.

This issue can be reproduced using [this data](https://community.cratedb.com/t/in-clause-on-primary-key-column-does-not-return-all-the-records-if-it-has-more-than-5k-inputs/1878/3)

We expect a single record in the result set since the database has only one record with the given ID. Below is a sample query and the corresponding Java code:

```auto
String query = "select * from uu.records where rday=? AND ( ( id IN ('161070') AND recordid=? ) OR ( id IN ('161070') AND recordid=? ) )";
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try{
            List<Object> ids = new ArrayList<>();
            con = getCrateConnection();
            ps = con.prepareStatement(query);

            ps.setLong(1, 1727375400000L);
            ps.setLong(2, 110);
            ps.setLong(3, 110);

            rs = ps.executeQuery();
            while(rs.next()){
                ids.add(rs.getString(1));
            }
            System.out.println("Number of records: " + ids.size());

        }catch (Exception e){
            e.printStackTrace();
        }

```

---

<div class="post-metadata">

**Author:** ![hernanc](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/hernanc/32/676_2.png) [@hernanc](https://community.cratedb.com/u/hernanc)\
**Post date:** [January 23, 2025, 2:43pm UTC](https://community.cratedb.com/t/prepared-statement-query-returns-duplicate-records-but-cratedb-console-query-doesn-t/1966/2 "2025-01-23T14:43:08Z")

</div>

Just in case anyone comes across this thread, this is now being reviewed under [Prepared Statement Query Returns Duplicate Records. CrateDB Console Query works fine. · Issue #17266 · crate/crate · GitHub](https://github.com/crate/crate/issues/17266)
