Sql top 10 interview questions for freshers

javatcorner.com Avatar

Here are five common SQL interview questions that are often asked of freshers:

  1. What is SQL?
    • SQL stands for Structured Query Language. It is a language used to interact with databases. With SQL, you can create databases, tables, retrieve data, update records, and more. It’s an ANSI standard language that communicates with various database management systems like MySQL, Oracle, and PostgreSQL.
  2. What is a database?
    • database is a structured form of data storage on a computer. It consists of schemas, tables, queries, views, and more. Databases allow us to easily store, access, and manipulate data.
  3. Does SQL support programming language features?
    • SQL is not a programming language; it is a command language. Unlike programming languages, SQL lacks conditional statements like loops or if-else constructs. Instead, it provides commands for querying, updating, and deleting data in the database.
  4. Difference between CHAR and VARCHAR2 datatype in SQL:
    • CHAR is used for fixed-length character strings, while VARCHAR2 is used for variable-length character strings. For example, if you define a column as CHAR(5), it will always store strings of exactly 5 characters. In contrast, VARCHAR2(5) allows variable-length strings.
  5. What is data definition language (DDL)?
    • DDL includes commands like CREATEDROP, and ALTER. These queries define the structure of data, such as creating tables or modifying their properties.
  6. What is a JOIN in SQL?
    • JOIN combines data from two or more tables based on a common column. It allows you to use data from multiple tables simultaneously. There are different types of JOINs, such as INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
    • Example: To retrieve data from the football_players and national_teams tables, you can use an INNER JOIN on the national_team_id column.
  7. What is a subquery in SQL?
    • subquery (also known as a nested query) is a query embedded within another query. It allows you to retrieve data from one table based on the results of another query. Subqueries are often used in WHERE or HAVING clauses.
    • Example: To find the average GPA of students who play more than 30 games, you can use a subquery.
  8. What are window functions in SQL?
    • Window functions perform calculations across a set of rows related to the current row. They allow you to create running totals, rankings, and moving averages. Common window functions include RANK(), DENSE_RANK(), and SUM() OVER().
    • Example: To compute the cumulative GPA for each student, you can use a window function.
  9. What’s the difference between ROWS and RANGE in window functions?
    • In window functions, ROWS and RANGE define the window frame. ROWS specifies a fixed number of rows, while RANGE defines a range of values based on the order of rows. The choice between them depends on the specific use case.
    • Example: To calculate a moving average, you might use RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING.
  10. How do you create a ranking in SQL?
    • You can create rankings using the RANK() or DENSE_RANK() window functions. RANK() assigns the same rank to equal values, while DENSE_RANK() leaves no gaps in ranking. Both functions order rows based on specified columns.
    • Example: To rank students by GPA, you can use the RANK() function.
javatcorner.com Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *

More Articles & Posts