Swarali Sree has Published 75 Articles

How can group functions be used in ORDER BY clause?

Swarali Sree

Swarali Sree

Updated on 22-Jun-2020 07:56:21

78 Views

We can sort the result set groups by using group functions in the ORDER BY clause. By default, the sort order is ascending but we can reverse it by using DESC keyword.Examplemysql> Select designation, YEAR(Doj), count(*) from employees GROUP BY designation, YEAR(DoJ) ORDER BY Count(*) DESC; +-------------+-----------+----------+ | designation | ... Read More

How can I use MySQL INTERVAL() function with a column of a table?

Swarali Sree

Swarali Sree

Updated on 22-Jun-2020 06:53:46

300 Views

We can use INTERVAL() function with a column of a table by providing the first argument as the name of the column. In this case, al the values in that column would be compared with the values given as the other arguments of INTERVAL() function and on that basis of ... Read More

In MySQL, how can we insert a substring at the specified position in a string?

Swarali Sree

Swarali Sree

Updated on 22-Jun-2020 06:04:46

460 Views

We can use a MySQL INSERT() function to insert a substring at the specified position in a string.SyntaxINSERT(original_string, @pos, @len, new_string)Here, original_string is the string in which we want to insert a new string at the place of some specific number of characters.@pos is the position at which the insertion ... Read More

How can we find the index position of a string stored as a record in MySQL table’s column?

Swarali Sree

Swarali Sree

Updated on 22-Jun-2020 05:10:22

91 Views

We can use FIELD() function to find the index position of a string stored as a record in MySQL table’s column. To demonstrate it we are using the table named ‘websites’ having the following dataExamplemysql> Select * from websites; +----+---------------+------------------------+ | Id | Purpose       | Webaddress   ... Read More

How can I insert a value in a column at the place of NULL using MySQL COALESCE() function?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 12:59:12

562 Views

To understand it, we are using the data from the table ‘Employee’ having Salary=NULL for ID = 5 and 6, as follows −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000 ... Read More

When MySQL FIND_IN_SET() function returns NULL as output?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 08:46:53

190 Views

FIND_IN_SET() function returns NULL as output if any of the argument i.e. either search string or string list, is NULL. Of course, It will also return NULL if both of the arguments are NULL.Examplemysql> Select FIND_IN_SET(NULL, 'Ram is a good boy') AS Result; +--------+ | Result | +--------+ | NULL ... Read More

Which function in MySQL returns the same output as BIN() function?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 08:11:07

53 Views

As we know that BIN() function returns the binary string of a number, of the DECIMAL base, after converting it into a binary value. In this way, it can be considered same as CONV(N, 10, 2) function. It means the output of CONV(N, 10, 2) would be same as the ... Read More

How can we insert data into a MySQL table?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 07:34:22

346 Views

For inserting data into a MySQL table we need to use INSERT INTO command. We must have to specify values for all the columns of the table in INSERT INTO command.SyntaxINSERT INTO table_name values(value1, value2, …)ExampleSuppose we have a table named ‘Student’ with three columns ‘RollNo’, ‘Name’ and ‘Class’ then ... Read More

How can we use existing values of the rows to provide new values in the SET clause of UPDATE statement?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 07:05:10

99 Views

Existing values of the row can be used to provide new values in the SET clause if that row matches the WHERE clause in an UPDATE statement. Following is the example to demonstrate it.ExampleSuppose we have a table named ‘tender’ as follows −mysql> Select * from tender; +-----------+---------+------+ | tender_id ... Read More

How can we use group functions with non-group fields in MySQL SELECT query?

Swarali Sree

Swarali Sree

Updated on 20-Jun-2020 06:33:44

113 Views

We have to use GROUP BY clause if we want to use group functions with non-group fields in the SELECT query. The general syntax can be as followsSyntaxSELECT group_function1, …, non-group-column1, … from table_name GROUP BY column_name;Examplemysql> Select COUNT(*), id from Student GROUP BY id; +----------+------+ | COUNT(*) | id ... Read More

Advertisements