WHERE DEPARTMENT = 'Finance'
. But what if there are some records with DEPARTMENT = 'finance'
? Or DEPARTMENT = 'FINANCE'
? In the best case, you don't get any results and immediately realize that you made a mistake. In the worst case, you actually do get results, but you miss a lot of records WITHOUT REALIZING IT.GROUP BY DEPARTMENT
to get all distinct values for DEPARTMENT. This will typically let you see whether there are any other versions of the category 'Finance'
that you need to be aware of. Please note that this can change in the future, so even better than checking the distinct values once would be to do a simple pre-processing on the text field. You can simple use WHERE UPPER(DEPARTMENT) = 'FINANCE'
, which will be true for 'Finance'
, 'finance'
, 'FINANCE'
and even 'FInance'
.SELECT sales FROM mydb.monthly_sales
or SELECT SALES FROM MYDB.MONTHLY_SALES
. As mentioned before, SQL is case insensitive, so it doesn't make a difference. However, when I tried to query the table that contains all column names for all tables, DBC.TABLESV
, I couldn't find the column named 'SALES'
. The following query returned zero rows.TABLENAME = 'monthly_sales'
and COLUMNNAME = 'sales'
. This means that your code style - that should be free for you to choose - actually influences how the database stores the column names. This is very unfortunate and can lead to some annoying side effects, so I recommend writing queries in all upper case to avoid this problem.