Querying for Data

21 important questions on Querying for Data

What is the syntax of a SELECT statement?

SELECT values_to_display FROM table_name WHERE expression GROUP BY how_to_group HAVING expression ORDER BY how_to_sort LIMIT row_count;

When should you not use * in a SELECT statement?

1. When you don't want all columns
2. When you want the columns in a different order

What SELECT clause does not support aliases?

The WHERE clause
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What is the syntax of the BETWEEN operator?

SELECT * FROM  world.`Country` WHERE Population BETWEEN 10 AND 20;

In what order are the rows in a resultset ordered by default?

No specific ordering

Does ORDER BY `col`, `col2` DESC sort both columns descending?

No, col ASC and col2 DESC

Can you specify an ORDER BY statement on the column index, for example ORDER BY 1 ASC, 2 DESC?

Yes

Can you use aliases in a MySQL ORDER BY statement?

Yes

A temporal column sorted ascending begins with earliest or latest date?

Earliest date

What defines the sort order of binary strings?

The numeric values of the bytes in the data

What determines the sort order of ENUMs and SETs?

The internal numeric values of the values in the set or enum

Can you use expressions in a LIMIT statement?

No

What is the difference between binary and non-binary strings when using the DISTINCT operator?

Binary is case-sensitive
Non-binary is case-sensitive based on the collation

What is the difference between DISTINCT and a GROUP BY without summarize?

GROUP BY causes sorting

Do the MIN() and MAX() function work on string and temporal fields?

Yes

Does COUNT(`col`) include NULL values?

No

How do you change the separator of GROUP_CONCAT?

GROUP_CONCAT(col SEPARATOR ' - ')

How do you change the order of a GROUP_CONCAT?

GROUP_CONCAT(col ORDER BY col DESC)

Why would you add an ORDER BY statement to a GROUP BY statement if the effective ordering is the same?

For portability

What does the WITH ROLLUP statement do for a GROUP BY statement?

Adds a row with the overall data for the aggregate functions

Does a UNION statement require the tables to have exactly the same structure?

No

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo