Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rajeshtva's avatar

What is FUNCTIONS keyword doing in mysql query?

I have this SQL query. which is a solution to this hackerrank sql problem.

SELECT X,
       Y
FROM FUNCTIONS F1
WHERE EXISTS
    (SELECT *
     FROM FUNCTIONS F2
     WHERE F2.Y = F1.X
       AND F2.X = F1.Y
       AND F2.X > F1.X)
  AND (X != Y)
UNION
SELECT X,
       Y
FROM FUNCTIONS F1
WHERE X = Y
  AND (
         (SELECT COUNT(*)
          FROM FUNCTIONS
          WHERE X = F1.X
            AND Y = F1.X) > 1)
ORDER BY X;

but i can't find any explanation of this FUNCTIONS keyword. So I request for this to be explained. Thank You.

0 likes
9 replies
siangboon's avatar

Not so sure, but seem like a syntax to declare the following code as a function and naming it so you can refer in the query.

wingly's avatar
wingly
Best Answer
Level 29

that's simply the name of the table

Sinnbeck's avatar

It is even the very first sentence

You are given a table, Functions

1 like
Tray2's avatar

@sinnbeck is correct, the query is using a table called functions , which is in my opinion a stupid name for a table.

The answer from @cooke69 is not correct in this case since it's clearly a table, however you can just like he says create functions in the database. The database uses language called PL/SQL (when using SQL Server it's called TSQL), which is a programming language with a Pascal like syntax that you can create functions and procedures with.

Please or to participate in this conversation.