Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interesting SQL quiz

Tags:

sql

Recently I came across with the following quiz. Imagine we have this table

+--------+
| colors |
+--------+
| red    |
| black  |
| white  |
| green  |
| orange |
+--------+

The task is to write a SQL query that will select all pairs without allowing duplicates. Permutations are counted too ({red, black} = {black, red}, hence only one of the pair is allowed).

like image 323
glaz666 Avatar asked Jul 28 '09 19:07

glaz666


People also ask

What is SQL very short answer?

Answer: SQL is a Structured Query Language that is used for manipulating and accessing the relational database. On the other hand, MySQL itself is a relational database that uses SQL as the standard database language.

How do I memorize SQL queries?

So try to memorise the following consecutive statements: SELECT→FROM→WHERE. Next, remember that the SELECT statement refers to the column names, the FROM keyword refers to the table/database used, and the WHERE clause refers to specific conditions that are investigated by the user.


1 Answers

Try this

Select A.Color, B.Color
From Colors A
Cross Join Colors B
Where A.Color > B.Color
like image 78
Charles Bretana Avatar answered Sep 18 '22 21:09

Charles Bretana