# Having a label as a parameter in a cypher query (efficiently)

**URL:** <https://community.neo4j.com/t/having-a-label-as-a-parameter-in-a-cypher-query-efficiently/59620>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [October 3, 2020, 9:32pm UTC](https://community.neo4j.com/t/having-a-label-as-a-parameter-in-a-cypher-query-efficiently/59620 "2020-10-03T21:32:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roymaor1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/roymaor1/32/4107_2.png) [@roymaor1](https://community.neo4j.com/u/roymaor1)\
**Post date:** [October 3, 2020, 9:32pm UTC](https://community.neo4j.com/t/having-a-label-as-a-parameter-in-a-cypher-query-efficiently/59620/1 "2020-10-03T21:32:29Z")

</div>

Hello all,

I am looking for a way to get a label as a string from my user **AND** use the label optimization in my query (rather than have the engine go for a full DB scan).

2 ways I have found so far of doing so (I'll use the WITH keyword to simulate user input):  
1.

```auto
WITH "facebook" as company
MATCH p = (a:company)-->(b:company)
RETURN p

```

This one just won't work, as cypher apparently does not know how to handle form of (node\_name:label\_name) when label\_name is a parameter.

```auto
WITH "facebook" as company
MATCH p = (a)-->(b)
WHERE ALL (x IN nodes(p) WHERE company IN labels(x))
RETURN p

```

This one works, but performs a full DB scan, not using the label optimization benefit for improved performance.

Any ideas?  
Thanks!

---

<div class="post-metadata">

**Author:** ![danielfrees](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@danielfrees](https://community.neo4j.com/u/danielfrees)\
**Post date:** [September 27, 2022, 7:54pm UTC](https://community.neo4j.com/t/having-a-label-as-a-parameter-in-a-cypher-query-efficiently/59620/2 "2022-09-27T19:54:57Z")

</div>

Nevermind on my original reply. Can't see how to delete this lol.
