SQL

How to find the length of a string in SQL?

To return or fetch the length of the value in a text field, the LEN() function is used.   SQL LEN() Syntax is as follows: Select LEN(column_name) From table_name;   Let us consider the below Students table: roll_no Name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti 502 83.60 A 4 Kaushik 337 56.10 C   Suppose we want to

How to fetch the last value of a column in SQL?

To return or fetch the last value of the selected column, the LAST() function is used.   SQL LAST() Syntax is as follows: Select Last (column_name) From table_name;   Note: The LAST() function is only supported in MS Access.   Let us consider the below Students table: roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti 502 83.60 A 4

How to format a particular column in SQL?

In order to format how a column is to be displayed, the FORMAT() function is used.   SQL FORMAT() Syntax is as follows: Select Format(column_name, format) From table_name;   Let us consider the following Students table:   roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti 502 83.60 A 4 Kaushik 337 56.10 C   Example: The following SQL

How to fetch the first value of a column in SQL?

To return or fetch the first value of the selected column, the FIRST() function is used.   SQL FIRST() Syntax: Select First(column_name) From table_name;   Note: The FIRST() function is only supported in MS Access.   Let us consider the below Students table: roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti 502 83.60 A 4 Kaushik 337 56.10 C

How to count the number of records in SQL?

To return the number of rows that are matching a specifies criteria, the COUNT() function is used.   The Syntax is as follows: Sql Count(Column_Name) From table_name; Count (column_name) function returns the number of values The values that are mentioned as NULL will not be counted for that specified column.   Example: Let us consider the Students table: roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33

How to Concat Strings in SQL?

If you want to form a single string from two or more strings, then Concat() Function is used. Select statement can be used to call the Concat() Function. The Contact() Syntax is as follows: Select Concat(column_name1, column_name2, .., column_nameN) From table_name;   Let us consider the following Students table:   roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti

How to calculate an average in SQL?

To return the average value of a column that has numeric values, AVG() function is used.  AVG() Syntax is as follows: Select AVG (column_name) From table_name;   Let us consider the following Students table:   roll_no name total_marks (out of 600) percentage grade 1 Ashok 392 65.33 B 2 Chaitali 454 75.67 A 3 Smriti 502 83.60 A 4 Kaushik 337 56.10 C   Example: The following SQL statement gets

How to use a Where Clause in SQL?

While fetching or retrieving the data from a single table or with multiple tables, the SQL WHERE clause is used. In order to return value from the table, the given condition should be fulfilled. Where Clause is used to sort the data and retrieve only the necessary records. The Where Clause is not only used in combination with Select Statement, but also with the Update Statement, Delete Statement and so on.  

How to update a table using SQL Update?

To make any changes in the existing data of the table, SQL UPDATE Query is used. Combine UPDATE Query with the WHERE Clause to modify selected records, otherwise all the data records will be affected.   Syntax: The UPDATE Query Syntax is as follows: UPDATE table_name Set column1 = value1, column2 = value2, ……, columnN = valueN WHERE condition;   You can combine N number of conditions using AND or

How to Truncate a Table in SQL?

In order to delete or empty the entire data from a particular existing table, the SQL TRUNCATE TABLE command is used. The difference between the Drop Table and Truncate Table is that, when you use Drop Table statement the entire table structure along with its data gets deleted, Wherein when you use Truncate Table Statement, the entire data gets deleted retaining the table structure.   The syntax of TRUNCATE TABLE is: Truncate Table table_name;