Which clause is mandatory in SQL?

The SQL Select Statement:

Microsoft Access is a Visual Basic based application that allows the SQL statements to be embedded in VBA code and macros. One of the most used SQL statements, the SELECT statement, provides the much needed flexibility in the retrieval of data from a database. The general form of the SELECT command is:

SELECT select_list FROM source [ WHERE condition(s) ] [ GROUP BY expression ] [ HAVING condition ] [ ORDER BY expression ] ;
  • The SELECT statement indicates that you which to query and retrieve information from a database. The select_list specifies the type of information (or column names) to retrieve. The keyword ALL or the wildcard character asterisk (*) could be used to signify all columns in the database. Also, the keyword DISTINCT could be used to discard duplicate records and retrieve only the unique records for the specified columns.
  • The FROM clause is the only required clause in the SELECT statement. The FROM clause specifies the specific database tables to retrieve data from.
  • The WHERE clause limits the results to those records (or rows) that meet some particular conditions (optional).
  • The GROUP BY clause specifies the format of the output. The expression specifies a column listing such that all rows contained in the specified columns will be aggregated together (optional).
  • The HAVING clause specifies the specific conditions to group by (optional).
  • The ORDER BY clause specifies whether to output the query result in ascending or descending order. The expression specifies a column listing to order by (optional).

The select statement, like all other SQL statements, should end with a semi-colon. The semi-colon terminates a statement. If you wanted to select an entire table, every record and every field, the command would be:

SELECT * FROM source; or SELECT ALL FROM source;

The absence of the WHERE clause signifies that there are no restrictions to be placed on the rows, so display all rows. This query statement can be further modified to indicate specific fields (or columns) and specific records (or rows) to retrieve, and also set limitations on, the queried results using the WHERE clause. The absence of the GROUP BY, HAVING and ORDER BY clauses signifies that there are no particulars restrictions to be put on the output of the query.

The optional conditions may make use of comparison operators, which include the following:

COMPARISON OPERATORS
= Equal To
> Greater Than
< Less Than
>= Greater Than or Equal To
<= Less Than or Equal To
<> Not Equal To
LIKE String Comparison Test

Aggregate functions can be included to perform computations on numeric values. Aggregate functions include the following:

AGGREGATE FUNCTIONS
MIN Returns the smallest value in a given column
MAX Returns the largest value in a given column
SUM Returns the sum of the numeric values in a given column
AVG Returns the average value of a given column
COUNT Returns the total number of values in a given column
COUNT(*) Returns the number of rows in a table

This set of MySQL Multiple Choice Questions & Answers (MCQs) focuses on “The select Clauses – 1”.

1. What is the meaning of “SELECT” clause in Mysql?
a) Show me all Columns and rows
b) Show me all columns
c) Show me all rows
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

2. Which of the following clause is evaluated in the last by database server?
a) SELECT
b) WHERE
c) FROM
d) None of the mentioned
View Answer

Answer: a
Explanation: “SELECT” clause is used to show all rows or columns therefore it evaluated at last.

3. What will be the output of the following SQL statement?

a) Show all rows and columns of table “person”
b) Show all rows of table “person”
c) Show all columns of table “person”
d) None of the mentioned
View Answer

Answer:a
Explanation: “SELECT” clause is used to show all rows or columns.

4. What will be the output of of the following SQL statement?

SELECT person_id, Fname, lname FROM person;

a) Show only columns (person_id, Fname, lname) and rows related to these columns
b) Show only columns (person_id, Fname, lname)
c) Show all rows
d) Show all columns except (person_id, Fname, lname)
View Answer

Answer: a
Explanation: “SELECT” clause is used to show all rows and columns that are mention with the query.

5. Can “SELECT” clause be used without the clause “FROM”?
a) YES
b) NO
c) DEPENDS
d) None of the mentioned
View Answer

Answer: b
Explanation: “SELECT” clause is used to show rows and columns of a particular table and clause “from” is used to denote a table name.

6. Find the error in the following SQL statement?

a) No Error
b) No table mentioned
c) Depends
d) None of the mentioned
View Answer

Answer: b
Explanation: “SELECT” clause cannot be used without clause “FROM”.

7. What will be the output of the following SQL statement?

SELECT * FROM person WHERE person_id=1;

a) Show all columns but only those rows which belongs to person_id=1
b) Show all columns and rows
c) Shows only columns person_id
d) None of the mentioned
View Answer

Answer: a
Explanation: Clause “WHERE” is also used, which tells the compiler to show only that rows which belong to person_id=1.

8. What will be the output of the following SQL statement?

SELECT person_id, fname, lname FROM person WHERE person_id=1;

a) Show only columns(person_id, fname, lname) but only those rows which belongs to person_id=1
b) Show all columns and rows
c) Shows only columns person_id
d) None of the mentioned
View Answer

Answer: a
Explanation: Clause “WHERE” is also used, which tells the compiler to show only that rows which are belong to person_id=1.

9. Which clause is mandatory with clause “SELECT” in Mysql?
a) FROM
b) WHERE
c) Both FROM and WHERE
d) None of the mentioned
View Answer

Answer: a
Explanation: “SELECT” clause cannot be used without clause “FROM”.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.

Next Steps:

  • Get Free Certificate of Merit in MySQL
  • Participate in MySQL Certification Contest
  • Become a Top Ranker in MySQL
  • Take MySQL Tests
  • Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Which clause is mandatory in SQL?

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.

Which of the following clauses are mandatory in a SQL query?

Which of the following clauses are mandatory in an SQL query? Answer: A. SELECT and FROM are the mandatory clauses in a SELECT query.

What two clauses are mandatory in a SELECT statement?

Each SQL query statement must contain both a SELECT and a FROM clause. The combination of these two clauses determine the table columns that are searched by the query. The WHERE clause and other advanced clauses further limit data retrieval to specific table rows.

What are the 3 main clauses of a SQL statement?

SQL clauses.
CONSTRAINT clause..
FOR UPDATE clause..
FROM clause..
GROUP BY clause..
HAVING clause..
ORDER BY clause..
The result offset and fetch first clauses..
USING clause..

What is an optional clause in SQL?

Specifies that the indicated query hint should be used throughout the entire query. Each query hint can be specified only one time, although multiple query hints are permitted. Only one OPTION clause can be specified with the statement. This clause can be specified in the SELECT, DELETE, UPDATE and MERGE statements.