Anda di halaman 1dari 5

ANSI-SQL

Commonly made mistakes in Ebox Certification.

The list of mistakes that the trainees are doing during their ANSI SQL Ebox Certification which
has been prepared based on their reports from Ebox.

8/14/2015

0
Commonly made mistakes:

COMMONLY MADE MISTAKES DUE TO NEGLIGENCE:

 ALIAS Names

o ALIAS name not given as mentioned in the question


o Typo error in ALIAS name. For example,
 Expected: MODERATE Found: MODURATE,
 Expected: BOOKTITLELENGTH found: BOOKTITLELENGHT
 Expected: SUPPLIER_NAME_LENGTH found: SUPPILER_NAME_LENGTH

 Columns selection

o Do not select extra columns


o Do not miss any column
o Do not select the wrong column
o Avoid usage of Select *and instead list columns

 Others

o Ensure DISTINCT is used only when it’s necessary


o Ensure all the conditions given in the problem statement are implemented. For
example, "length is less than 15 letters" condition is not implemented. "Permanent"
condition is missed.
o Ensure comparisons are correct. Ex: A trainee has used >1 instead of >=1
o Ensure sorting is correct. Trainee have missed DESC keyword for sorting the records in
descending order
o Don’t get confused between the usage of ascending and descending keywords while
sorting the columns
o Sorting logic itself is missed out as it’s mostly implemented at the end of the query i.e.
Order by clause logic not applied
o Use TRIM wherever necessary
o Ensure comparisons are done correctly. Sometimes trainee have used LIKE when they
are supposed to use NOT LIKE
o Ensure proper joins are used to connect tables in order to fetch the required data
o Before completing the test, ensure all queries are correct

COMMONLY MADE TECHNICAL MISTAKES:


 Understanding of the problem

o Clear understanding of the given Database schema and its relationship representations

1
even before attempting the questions

o Analyze the tables and understand the case study table structure before writing queries.
For Ex: There might be 10 books in a library, but it is not necessary that all the books
have been taken at least once. Hence join should not be used between these two tables.

 Usage of “Group by:

o When there are non-aggregate columns in the SELECT clause, those non-aggregated
columns should be included in GROUP BY clause.

o In case of MySQL both the query works:-

SELECT abc, efg, count (abc) from xyz table group by abc

[Note: The above query is only supported in MySQL and not a standard way of grouping.]

SELECT abc, efg, count (abc) from xyz table group by abc, efg

[Note: The above query is also supported and is a standard of grouping.]

[So this standard can be enforced by setting SET SQL_MODE="ONLY_FULL_GROUP_BY”]

 If you use any function for a column for which the ALIAS name is not specified in the question,
then provide the column name as the ALIAS name.

o Ex: Question: select the contact and the name of employees. Print ‘N/A’ if contact is not
available.(if mentioned in the question)
Select IFNULL (B.CONTACT,'N/A'), emp_name from employee
o In the above case, ALIAS is not specified in the question, but a function is being used in
the query. Hence use the column name as ALIAS
o Correct Query is
Select IFNULL (B.CONTACT,'N/A') CONTACT, emp_name from employee
 Other

o Usage of group by is wrong.


o While grouping, not necessary all the columns have to be used.
o Ensure the primary key join is done correctly
o Understand the difference between Sub queries and joins and its place of usage
o Ensure that the query written will be applicable for any dataset on which it is validated.
Do not hardcode to make it work for a single dataset alone.
o Do not unnecessarily complicate simple queries
o Do not join table until and unless you are selecting values or using that table for
comparison

2
Commonly made mistakes - Examples:

1. Added extra columns in the select clause which is not asked in the problem statement. For
example,
a. Problem statement is Write a query to display issue id, customer id, customer name
for the customers but the trainee’s query is select
b.issue_id,b.customer_id,c.customer_name,b.return_date,b.actual_date_of_return
2. Hardcoding – For example,
a. Problem is to find the customers who has taken movie more than once, but the trainee
has hardcoded the values of the customers who has taken movie more than once, like
this c.customer_id='C00004', But this is work fine in the default data but will fail in the
actual data which we use to validate the answers.
b. One more example, case c.contact_no when '9830354218' then '+91-983-035-4218'
when '8923156781' then '+91-892-315-6781'
when '9831289761' then '+91-983-128-9761' end as CONTACT_ISD,
3. Solution Query Failed to Execute Reason: MySQLSyntaxErrorException. For example,
a. select m.customer_name,coalesce(m.contact_no,m.contact_address) as
CONTACT_DETAILS,if(lm.card_id) is null from library_card_master lm,
lm.description from library_card_master lm
How will control statement work in the select clause?
b. if mm.movieid is NULL then '0'; - Trainee has put this condition after join without
“where” clause.
c. Select substring(id.issue_id ___%d) as SERIAL_NO – How will this work?
4. Incomplete Queries - select customer_id,customer_name,age,concat('+91','-',contact_no) from
customer_master – Which is not as per requirements.
5. Missed condition – For example,
a. Display the customers who has contact number, but many trainees missed this
condition in the query.
b. Display movies which are not issued to any customers, this condition is missed by many
trainees.
6. Query which is logically wrong.
7. Typo in the query
8. Solution Query Failed to Execute Reason: SQLException: Subquery returns more than 1 row. For
example,
a. Where director_name = ( select director_name from movies_master group by
director_name) – Always use “IN” clause. Default test data would have returned single
row, but actual data returned more than one row which resulted in failure. Many
trainees have made these mistakes.
9. Solution Query Failed to Execute Reason: MySQLSyntaxErrorException: Unknown column
'customer_id.cid' in 'field list'. For example,
a. Select customer_id.cid,sum(rental_cost) as TOTAL_COST from customer_issue_details

3
cid join – How will this work? Putting alias name after column name.
10. Duplicate rows – Missed primary key column matching in the query.
11. Wrong syntaxes – for example,
a. having coalesce(contact,address) – How will this work?

Anda mungkin juga menyukai