# Common SQL error troubleshooting tips in Looker

**URL:** <https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030>\
**Category:** Technical Tips & Tricks\
**Created:** [July 23, 2021, 7:39pm UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030 "2021-07-23T19:39:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LookerExperts](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/lookerexperts/32/109358_2.png) [@LookerExperts](https://discuss.google.dev/u/LookerExperts)\
**Post date:** [July 23, 2021, 7:39pm UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030/1 "2021-07-23T19:39:06Z")

</div>

## Overarching themes/questions:

Here is a list of common questions our users often need support with, along with troubleshooting steps to try out:

1. Why is my SQL query slow even when there are no queries queued on Looker?

- Run against database (or SQL Runner): check if that runs fast to see if it is a database problem or looker problem

- [Explain](https://help.looker.com/hc/en-us/articles/360023513514-How-to-Optimize-SQL-with-EXPLAIN) in SQL can help to optimize the query

- Check join logic, so we can make sure to avoid [fanouts](https://community.looker.com/technical-tips-tricks-1021/what-is-a-fanout-23327)

- Open up the generated SQL in SQL Runner to test your query

1. I have a part of a query, and I see there’s an error from this query. How can I find out which field is causing the error?

- Start by making the query less complex:

- Open up the generated SQL in SQL Runner to test your query/see a more detailed error message

- Search the SQL database dialect docs for the functions we are using to ensure that we are using correct syntax

- Check to see if the database name is included in the error surfaced on the explore.

- Are we able to run the query in the database without error?

1. Why is Looker’s generated SQL different from the one I usually write?

- [Symmetric aggregates](https://help.looker.com/hc/en-us/articles/360023722974-A-Simple-Explanation-of-Symmetric-Aggregates-or-Why-On-Earth-Does-My-SQL-Look-Like-That-): They help to prevent miscalculating aggregates, but also add in a lot of complex looking code in the generated SQL

- [Value format](https://docs.looker.com/reference/field-params/value_format)

1. What does a particular SQL error mean? (function missing, data type mismatch, etc)

- Is there a data type mismatch between what we have written versus the data types that are required for the function, per the database dialect documentation?

- Are we using the correct function for the database dialect?

- Google the error: there are lots of online forums that can provide context

- Open up the generated SQL in SQL Runner to test your query

## 

## Specific/Common Errors:

So we just went over the overarching themes that we can run into when working with complex SQL. However, there are times when we might run into errors that are very specific to the query we are working with. Here are the top few errors we may run into, we use MySQL here as an example, the error messages from other SQL dialects can be very similar:

Error 1:

**SQL Syntax Error: The MySQL database encountered an error while running this query.**

**(conn=95374054) Unknown column ‘users.city’ in ‘field list’**

**So what does this error mean?**

The database is throwing an error stating that the column we’re referencing in the `sql` parameter of a field isn’t being found. Therefore, there are a few things we can check for here:

**Steps to troubleshoot:**

- Narrow down the field(s) the error is coming from and identify the table in the database that the error is coming from

- Run a `SELECT * FROM LIMIT 5;` to view a list of columns in the table. Check if the column in question exists in your table.

---

<div class="post-metadata">

**Author:** ![xin](https://avatars.discourse-cdn.com/v4/letter/x/bbce88/32.png) [@xin](https://discuss.google.dev/u/xin)\
**Post date:** [July 23, 2021, 7:40pm UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030/2 "2021-07-23T19:40:35Z")

</div>

Thanks @Sal and @shivanisankar for creating this article!

---

<div class="post-metadata">

**Author:** ![ryanpisuena](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@ryanpisuena](https://discuss.google.dev/u/ryanpisuena)\
**Post date:** [July 23, 2021, 7:51pm UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030/3 "2021-07-23T19:51:44Z")

</div>

![:clap:](https://d2yds90mtvelsl.cloudfront.net/original/3X/6/d/6db7ba128129c8e1160e03715b76c2e8bf67016d.png)

![:clap:](https://d2yds90mtvelsl.cloudfront.net/original/3X/6/d/6db7ba128129c8e1160e03715b76c2e8bf67016d.png)

![:clap:](https://d2yds90mtvelsl.cloudfront.net/original/3X/6/d/6db7ba128129c8e1160e03715b76c2e8bf67016d.png)

![:clap:](https://d2yds90mtvelsl.cloudfront.net/original/3X/6/d/6db7ba128129c8e1160e03715b76c2e8bf67016d.png)  
Great article!

---

<div class="post-metadata">

**Author:** ![Ismaila](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/ismaila/32/30170_2.png) [@Ismaila](https://discuss.google.dev/u/Ismaila)\
**Post date:** [July 23, 2021, 10:51pm UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030/4 "2021-07-23T22:51:41Z")

</div>

Well done putting this together folks!!  
 ![:clap:](https://d2yds90mtvelsl.cloudfront.net/original/3X/6/d/6db7ba128129c8e1160e03715b76c2e8bf67016d.png)

---

<div class="post-metadata">

**Author:** ![markjuan458](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/markjuan458/32/10064_2.png) [@markjuan458](https://discuss.google.dev/u/markjuan458)\
**Post date:** [October 20, 2021, 6:28am UTC](https://discuss.google.dev/t/common-sql-error-troubleshooting-tips-in-looker/119030/5 "2021-10-20T06:28:10Z")

</div>

One of the SQL System Functions that returns the severity of an error is SQL ERROR SEVERITY (if occurred). Within the context of a CATCH block, the ERROR SEVERITY function is used. This method will return NULL if called outside of the CATCH block [logo animation online](https://icreativesol.com/animated-logo-design/)
