SQL query doubt

Asked

Viewed 50 times

1

  • 1

    Do you expect people to have to follow the video to answer you? It would be nicer if you left the self-explanatory question and reproduced the whole example here.

1 answer

4


The function of the operator UNION is to return the DISTINCT RESULTS of 2 SELECTS or more ( to list also the repeated results is used UNION ALL )

An example of use would be to list all cities in a table client together with a table supplier

Example:

 SELECT cidade FROM Cliente UNION SELECT cidade FROM Fornecedor

If you have only 2 customers , 1 living in São Paulo and the other in Rio de Janeiro , and only 1 Supplier , from São Paulo the query will return:

São Paulo
Rio de Janeiro

Using UNION ALL for the same data:

Example :

 SELECT cidade FROM Cliente UNION ALL SELECT cidade FROM Fornecedor

Upshot:

São Paulo
São Paulo
Rio de Janeiro

The video it’s about SQL INJECTION

A page that displays 3 data appears and the author uses the UNION in a query string to display 1 , 2 and 3 instead of the original data. Then it replaces the code to steal data and credentials.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.