← Back to list

EXPLORING MYSQL

This was a question I encountered on HackerRank, which asked us to print stars in decreasing order based on the given input.

Shaaf Ahmed Kittur · 2026-04-18 19:13 · 0 claps · 1.8 min read
#sql #mysql #delimiters #loop #procedure
Open on Medium ↗

EXPLORING MYSQL

Draw a Triangle

Draw a Triangle

This was a question I encountered on HackerRank, which asked us to print stars in decreasing order based on the given input.

Initially, I had no idea what to do because I didn’t know that SQL also supports loops and conditions. I tried solving this problem by exploring methods on GeeksforGeeks, W3Schools, and other resources. There, I learned how to create a procedure, but I was unable to fully understand how it actually worked.

Lets see what this query is doing .

1 . The delimiter , which is nothing but what we use to end sentences in our programming languages like c , java, cpp use semicolon( ; ) as their delimiter.

2 . So we have to change the default delimiter to $$ from ; . And now you will be asking why , so first look at our procedure it consists of semicolon ( ; ) on every other line . The default behaviour of mySQL is it ends the statement on “ ; “, so if we don’t change this it can cause error.

3. Then we arrive at the Creation of procedure with syntax CREATE PROCEDURE procedure_name()

4. The two keywords BEGIN and END , define a block of code.

5. As we declare variables in c, java , python , similarly here we have declared variables i , j which are integer type and row_str which will store the array of stars.

6. The above while loop and it’s inner while loop is equivalent to :

i = 20

while i > 0:
    j = 1
    row_str = "" #Empty String

    while j <= i:
        row_str += "* " # Appending stars ' * '
        j = j + 1

    print(row_str)

    i = i - 1

7. After that we END $$ , we are using $$ because we changed the delimiter to $$ earlier from ; .

8. Now again we change the delimiter to ; .

  1. At the end we call the function.

Final Thoughts

This problem helped me realize that SQL is more powerful than I initially thought. It’s not just about queries — it also supports procedural programming concepts like loops, variables, and conditions.

THANK YOU!!!!!


메타데이터
post_id
6e29f1d8a4dc
slug
exploring-mysql-6e29f1d8a4dc
url
https://medium.com/@shaaf-ahmed/exploring-mysql-6e29f1d8a4dc
canonical_url
https://medium.com/@shaaf-ahmed/exploring-mysql-6e29f1d8a4dc
author_url
https://medium.com/@shaaf-ahmed
status
ok
fetched_at
2026-08-04 18:02:17