> For the complete documentation index, see [llms.txt](https://dshub.gitbook.io/ds-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dshub.gitbook.io/ds-hub/sql/sql-practice/popular-websites-for-sql-practice/hackerrank/sql-basic/type-of-triangle.md).

# Type of Triangle

Advanced SELECT

[Question Link](https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=false)

Write a query identifying the *type* of each record in the **TRIANGLES** table using its three side lengths. Output one of the following statements for each record in the table:

* **Equilateral**: It's a triangle with  sides of equal length.
* **Isosceles**: It's a triangle with  sides of equal length.
* **Scalene**: It's a triangle with  sides of differing lengths.
* **Not A Triangle**: The given values of *A*, *B*, and *C* don't form a triangle.

**Input Format**

The **TRIANGLES** table is described as follows:

![](https://s3.amazonaws.com/hr-challenge-images/12887/1443815629-ac2a843fb7-1.png)

Each row in the table denotes the lengths of each of a triangle's three sides.

**Sample Input**

![](https://s3.amazonaws.com/hr-challenge-images/12887/1443815827-cbfc1ca12b-2.png)

**Sample Output**

```
Isosceles
Equilateral
Scalene
Not A Triangle
```

**Explanation**

Values in the tuple ***(20,20,23)*** form an Isosceles triangle, because ***A=B***.&#x20;

Values in the tuple ***(20,20,20)*** form an Equilateral triangle, because ***A=B=C***.&#x20;

Values in the tuple  ***(20,21,22)*** form a Scalene triangle, because ***A≠B≠C***.&#x20;

Values in the tuple ***(13,14,30)*** cannot form a triangle because the combined value of sides ***A*** and  ***B*** is not larger than that of side ***C***.

<pre class="language-sql"><code class="lang-sql">SELECT 
    CASE
        WHEN (A+B&#x3C;=C OR B+C&#x3C;=A OR C+A&#x3C;=B) THEN 'Not A Triangle'
        WHEN (A=B AND B=C) THEN 'Equilateral'
        WHEN (A=B OR B=C OR C=A) THEN 'Isosceles'
        ELSE 'Scalene'
<strong>    END
</strong>FROM TRIANGLES 
</code></pre>
