# SQL Query errors

**URL:** https://discuss.elastic.co/t/sql-query-errors/222907
**Category:** Elasticsearch
**Tags:** elastic-stack-sql
**Created:** [March 10, 2020, 10:11am UTC](https://discuss.elastic.co/t/sql-query-errors/222907 "2020-03-10T10:11:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tangl](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@tangl](https://discuss.elastic.co/u/tangl)
#### Post date: [March 10, 2020, 10:11am UTC](https://discuss.elastic.co/t/sql-query-errors/222907/1 "2020-03-10T10:11:31Z")

</div>

Hi there, I have an index called "index-1". And l wanna to do a WHERE query, my sql query is as follow:

```auto
curl -X POST "xxx/_xpack/sql" -H 'Content-Type: application/json' -d "{\"query\": \"SELECT * FROM 'index-1' where id='x-1'\"}"

```

and l also tried

```auto
curl -X POST "xxx/_xpack/sql" -H 'Content-Type: application/json' -d '{"query": "SELECT * FROM \"index-1\" where id=x-1"}'

```

it seems that both of them are not correct, Is there anyone can help? Thanks in advance!

---

<div class="post-metadata">

### Author: ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)
#### Post date: [March 11, 2020, 8:49am UTC](https://discuss.elastic.co/t/sql-query-errors/222907/2 "2020-03-11T08:49:25Z")

</div>

Hi @tangl.

`i don't know what exactly you are implementing but i use like below for sql query- `

> POST:-  
> [http://localhost:9200/\_sql?format=txt](http://localhost:9200/_sql?format=txt)

> {  
> "query": "SELECT \* FROM dbdata where name='rahim' and id=101"  
> }

> POST:-  
> [http://localhost:9200/\_sql?format=txt](http://localhost:9200/_sql?format=txt)  
> {  
> "query": "SELECT \* FROM dbdataindex\_07\_08\_2019\_demo1 where id=101 "  
> }

Thanks  
HadoopHelp

---

<div class="post-metadata">

### Author: ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)
#### Post date: [March 11, 2020, 3:10pm UTC](https://discuss.elastic.co/t/sql-query-errors/222907/3 "2020-03-11T15:10:17Z")

</div>

@tangl

If you are trying to use 2 or more fields in the equality expression in the where clause, then this is semantically translated to a self join which is not supported.

---

<div class="post-metadata">

### Author: ![tangl](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@tangl](https://discuss.elastic.co/u/tangl)
#### Post date: [March 20, 2020, 8:07am UTC](https://discuss.elastic.co/t/sql-query-errors/222907/4 "2020-03-20T08:07:14Z")

</div>

no, l am using only 1 field in equality expression. The problem is both of the index name and id name has '-' which need to be escaped...but l don't find a way to do that...

---

<div class="post-metadata">

### Author: ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)
#### Post date: [March 20, 2020, 2:10pm UTC](https://discuss.elastic.co/t/sql-query-errors/222907/5 "2020-03-20T14:10:26Z")

</div>

```auto
curl -X POST "xxx/_xpack/sql" -H 'Content-Type: application/json' -d '{"query": "SELECT * FROM "index-1" where id='"'"'x-1'"'"'"}'

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 17, 2020, 2:10pm UTC](https://discuss.elastic.co/t/sql-query-errors/222907/6 "2020-04-17T14:10:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
