We've this query:
SELECT t FROM articles t WHERE t.article_id = 59446
Also known as:
SELECT articles FROM articles WHERE articles.article_id = 59446
I can not understand
SELECT articles FROM articles
What does this mean? Why it works?
Update: table 'articles' does not have column 'articles'
By using UNION, UNION ALL, EXCEPT, and INTERSECT, we can compare two queries and get the necessary output as per our requirement. Given examples are simple to follow, we can have complex queries and can apply the mentioned constructs in them and can compare.
---- A SQL statement could be a query and a query could be a SQL statement... but, these are most definitely NOT the same or synonymous. A query can refer to any request for data based on various types of filtering criteria, projection, sorting, paging, size, etc instructions.
Comparing the Results of the Two Queries The solution to this is very simple. Run both queries using a UNION to combine the results! The UNION operator returns unique records. If the two results sets are identical the row count will remain the same as the original query.
This is a result of Postgres' object-relational architecture. For every table you create, there is also a matching composite type with the same name.
When you run
SELECT articles
FROM articles
you are selecting a single column with the type articles
from the table named articles
. If you pay close attention to the output of that query you will notice that your result only contains a single column where the value is enclosed in parentheses, e.g. (1,Foobar)
(if the table articles has two columns). If you run select * from articles
the output is two columns (and no parentheses)
The same thing happens when you put the list of columns between parentheses:
select (article_id, article_name)
from articles
also returns a single column with an anonymous composite type containing two fields (this is also a good example that "column" and "field" is not the same thing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With