USER

USER is a SQL keyword that returns the name of the current user in the database management system. This function doesn't require any parameters. It's useful for permissions, auditing, and other user-specific context within a session.

Example

SELECT *
FROM students
WHERE grade = 'A';

Output

| Student_ID | Name | Grade |
|------------|-------|-------|
| 1 | Alice | A |
| 3 | Emma | A |
| 6 | Mike | A |

Explanation

In the provided SQL query, we select all fields from the ‘students’ table where the grade is ‘A’. The output is formatted into markdown to display the data in a table format. It shows that students with ID 1, 3, and 6, called Alice, Emma, and Mike respectively, have a grade ‘A’.

Example

SELECT ename, job
FROM emp
WHERE deptno=20;

Output

ENAME JOB
---------- ----------
JONES MANAGER
FORD ANALYST
SMITH CLERK

Explanation

In the example above, the query selects ename (employee name) and job from the emp table where the deptno (department number) is 20. The output table displays the names and jobs of all employees in department 20.

Example

SELECT *
FROM Customers
WHERE Country = 'USA';

Output

| CustomerID | ContactName | Country | Phone |
|------------|-------------|---------|-------------|
| 1 | John Smith | USA | 123-456-789 |
| 2 | Jane Doe | USA | 098-765-432 |

Explanation

In the SQL query, we select all fields (*) from the Customers table where the Country equals ‘USA’. The result of this query is outputted in a markdown table format, listing customers from the table ‘Customers’ that reside in ‘USA’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.