I understand that with such a question you can get a queue of minuses, but there is nowhere else to turn. In the course work on databases you need to find 15 different SELECT query structures. In bnf notation:

Selection statement :: = Table expression [ ORDER BY {{Name of the result column [ ASC | DESC ]} | {Positive integer [ ASC | DESC ]}}., ..];

Table expression :: =

Select expression

[

{ UNION | INTERSECT | EXCEPT } [ALL]

{Select-expression | TABLE Table Name | Table value constructor}]

Select-expression :: =

SELECT [ ALL | DISTINCT ]

{{{Scalar expression | Aggregation function | Select-expression} [AS Column Name]}., ..}

| {{Table Name | Correlation Name}. *}

| *

FROM {

{Table Name [ AS ] [Correlation Name] [(Column Name., ..)]}

| {Select-expression [ AS ] Correlation Name [(Column Name., ..)]}

| Join table}., ..

[ WHERE Conditional expression]

[ GROUP BY {[{Table Name | Correlation Name}.] Column Name}., ..]

[ HAVING Conditional expression]

the SELECT statement definitely has 13 of them, but I don’t see the last three point-blank ... I’ve found some of them already:

  1. The easiest SELECT + FROM + WHERE

  2. FROM subquery

  3. Subquery in SELECT

  4. Subquery in WHERE

  5. Using ORDER BY

  6. UNION | INTERSECT

  7. GROUP BY

  8. GROUP BY + Subquery in HAVING (At the same time GROUP BY + HAVING is just a complication of the structure, therefore it does not fit)

  9. Correlation request

  10. Using Aliases (ALIAS)

Since I create the database in the courseware in PostgreSQL, the capabilities of this DBMS can also be used, but for now I see the possibility to work only with FETCH in some way. Apparently the eye is already quite zamylilas, I will be very grateful if you point to the uncrowded.

  • If you understand, then why all the same publish the question? - 0xdb
  • In the hope that they will still tell you which structures I missed ... - tvs39

1 answer 1

Take the SELECT syntax and write elements from it for your list.

I just don't understand how you made your list. Why aliases are one element of the list separately from everything, and you mention the subqueries 5 times (a tabular subquery requires alias, for example), why having you have a group by attached and for some reason requires a subquery

 select 1 having false; 

Syntactically fully valid query, always returning 0 lines.

The easiest SELECT + FROM + WHERE

The simplest select looks like this:

 select; 

All this is the whole request and this is not a joke. Allowed since PostgreSQL 9.4, returns exactly one row with no data.

 select some_function(); 

Used everywhere when using stored functions.

 select 1 where some_condition(); 

Also valid request.

 select * from tablename; 

Of course, also a normal request. Therefore, I do not understand why you considered these different expressions as one and how you made a list.