# Sub-select with "spaceship operator" causes a error 1749

**URL:** <https://www.singlestore.com/forum/t/sub-select-with-spaceship-operator-causes-a-error-1749/4553>\
**Category:** Help\
**Tags:** community\
**Created:** [May 20, 2022, 12:21pm UTC](https://www.singlestore.com/forum/t/sub-select-with-spaceship-operator-causes-a-error-1749/4553 "2022-05-20T12:21:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heychazza](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/heychazza/32/2175_2.png) [@heychazza](https://www.singlestore.com/forum/u/heychazza)\
**Post date:** [May 20, 2022, 12:21pm UTC](https://www.singlestore.com/forum/t/sub-select-with-spaceship-operator-causes-a-error-1749/4553/1 "2022-05-20T12:21:25Z")

</div>

Hi all,

I’ve been writing a query which will pull in the unique players that each domain (from within my system), however I’m having an issue. Sometimes the `server_domain_id` can be null, so I added the “spaceship operator”, but now received an error.

Query:

```auto
SELECT
    COALESCE(server_domains.name, server_domains.ip) as nickname,
    player_sessions.server_id,
    count(*) AS total,
    (SELECT COUNT(DISTINCT player_id) FROM player_sessions ps2 WHERE player_sessions.server_domain_id <=> ps2.server_domain_id) as 'unique_players'
FROM
    player_sessions
LEFT JOIN
    server_domains ON player_sessions.server_domain_id = server_domains.id
WHERE
    quit_at BETWEEN "2022-05-10" AND "2022-05-17"
GROUP BY
    server_domains.id
ORDER BY
    total desc

```

Error:  
**ERROR 1749 ER\_DISTRIBUTED\_FEATURE\_LOCKDOWN:**  
**Feature 'Correlated subselect that can not be transformed and does not match**  
**on shard keys’ is not supported by SingleStore Distributed.**

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![MariaSilverhardt](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/mariasilverhardt/32/828_2.png) [@MariaSilverhardt](https://www.singlestore.com/forum/u/MariaSilverhardt)\
**Post date:** [May 25, 2022, 3:20pm UTC](https://www.singlestore.com/forum/t/sub-select-with-spaceship-operator-causes-a-error-1749/4553/2 "2022-05-25T15:20:42Z")

</div>

Hi Charlie! 🌞

Glad you asked about this. In this case…

(SELECT COUNT(DISTINCT player\_id) FROM player\_sessions ps2 WHERE player\_sessions.server\_domain\_id \<=\> ps2.server\_domain\_id) as ‘unique\_players’;

This type of subselect only works if the tables in the subselect match the shard key of the tables outside. Here we have a few options:

1. Avoid that type of subselect
2. Make the inner subselect’s table (player\_sessions) a reference table
3. Make player\_sessions and server\_domains match the shard key (e.g. make them shard on player\_sessions.server\_domain\_id and server\_domains.id)

Note that 2 and 3 would have impact on other queries on those tables.

Please let us know if this is helpful and keep us updated. Thanks 🙌

---

<div class="post-metadata">

**Author:** ![heychazza](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/heychazza/32/2175_2.png) [@heychazza](https://www.singlestore.com/forum/u/heychazza)\
**Post date:** [May 25, 2022, 3:57pm UTC](https://www.singlestore.com/forum/t/sub-select-with-spaceship-operator-causes-a-error-1749/4553/3 "2022-05-25T15:57:54Z")

</div>

Hey Maria!

Thanks for your time with the reply, annoyingly player\_sessions has a lot of data so modifying the table would probably be out the equation.

Is there any alternative to a subselect to query to get this figure? I know at worst I could just perform 2 separate queries and merge the data, but if I can do it in 1 then its even better.
