Skip to main content

Question: 2.

You want to display the titles of books that meet these criteria:

1. Purchased before January 21, 20012.

Price is less then $500 or greater than $900

You want to sort the results by their data of purchase, starting with the most recently boughtbook.

Which statement should you use?

A. SELECT book_title FROM books

WHERE price between 500 and 900

AND purchase_date < '21-JAN-2001'

ORDER BY purchase_date;

B. SELECT book_titleFROM books

WHERE price IN (500,900)

AND purchase_date < '21-JAN-2001'

ORDER BY purchase date ASC;
C. SELECT book_titleFROM books

WHERE price <> 900

AND purchase_date < '21-JAN-2001'

ORDER BY purchase date DESC;

D. SELECT book_titleFROM books

WHERE (price <> 900)

AND purchase_date < '21-JAN-2001'

ORDER BY purchase date DESC;


Answer: D
Explanation:

This statement provides required results.

Incorrect Answers:

A: This query will show books with price in range $500 and $900, not less then $500 or greater than $900.

B: This query will show books with prices exactly $500 or $900, not less then $500 or greaterthan $900.

C: This order will not show correct rows because of incorrect syntax in the WHERE clause.

Comments

Popular posts from this blog

21.Oracle - The self documenting dictionary

Oracle - The self documenting dictionary Oracle's Data dictionary is itself self documenting. we can query DICTIONARY AND DICT_COLUMNS views for descriptions of the data dictionary views and their columns. The following query gives the descriptions of all of the data dictionary views. SELECT table_name, comments FROM dictionary ORDER BY table_name; It gives the large amount of output. By using where class we can focus a smaller set of views as like the following query. SELECT table_name, comments FROM dictionary WHERE table_name LIKE '%TABLE%' ORDER BY table_name It returns all views containing the word 'TABLE' Like wise We can query the DICT_COLUMNS view also. It gives the descriptions for the columns for all views. Following query retrieves descriptions for the columns in ALL_TAB_COLUMNS. SELECT column_name, comments FROM dict_columns WHERE table_name = 'ALL_TAB_COLUMNS'; This is a sample one. We can learn lot about oracle through data d...

Question 9: null in where clause

The EMP table contains these columns: LAST NAME VARCHAR2(25) SALARY NUMBER(6,2) DEPARTMENT_ID NUMBER(6) You need to display the employees who have not been assigned to any department. You write the SELECT statement: SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement? A. The SQL statement displays the desired results. B. The column in the WHERE clause should be changed to display the desired results. C. The operator in the WHERE clause should be changed to display the desired results. D. The WHERE clause should be changed to use an outer join to display the desired results. Answer: C Explanation: The operator in the WHERE clause should be changed to display the desired results. There are times when you want to substitute a value in place of NULL. Oracle provides this functionality with a special function, called NVL(). You can use operation equal with the keywords IS NULL, or you can achieve desired results using NVL() fu...

Question 5: Where and having clauses

Which two statements are true about WHERE and HAVING clauses? (Choose two) A. A WHERE clause can be used to restrict both rows and groups. B. A WHERE clause can be used to restrict rows only. C. A HAVING clause can be used to restrict both rows and groups. D. A HAVING clause can be used to restrict groups only. Answer: B, C Explanation : HAVING clause to specify which groups are to be displayed and thus further restrict the groups on the basis of aggregate information. The Oracle server performs the following steps when youuse the Having clause 1. rows are grouped 2. the group function is applied to the group 3. the group that match the criteria in the Having clause are displayed. WHERE clause cannot be use to restrict groups HAVING clause use to restrict groups WHERE clause cannot be use when there is group functions. Incorrect Answers : A. Where clause cannot be use to restrict groups D. When HAVING clause is use rows are grouped as well.