- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
87 Views
To illustrate it we are using the following example of a table named ‘vistors’ which have the epoch as follows −mysql> Create table visitors(userid int not null, name varchar(20), epoch int NOT NULL); Query OK, 0 rows affected (0.42 sec) mysql> Insert into visitors Values(1, 'Gaurav', 1358658942); Query OK, 1 row affected (0.04 sec) mysql> Insert into visitors Values(2, 'Raman', 1358659585); Query OK, 1 row affected (0.04 sec) mysql> Select userid, name, FROM_UNIXTIME(epoch) from visitors; +--------+--------+----------------------+ | userid | name | FROM_UNIXTIME(epoch) | +--------+--------+----------------------+ | 1 | Gaurav | 2013-07-24 16:05:42 | | 2 | Raman | 2013-07-24 16:16:25 | +--------+--------+----------------------+ 2 rows in set (0.00 sec)
114 Views
Group functions are the function which applied to a group of rows or in other words group functions operate on sets of values. The following table gives the Description of MySQL group functions −Sr.No.Name & Description1AVG()It returns the average value of the argument.2BIT_AND()It returns bitwise AND.3BIT_ORIt returns bitwise OR.4BIT_XOR()It returns bitwise XOR.5COUNT()It returns a count of the number of rows returned.6COUNT(DISTINCT)It returns the count of a number of different values.7GROUP_CONCAT()It returns a concatenated string.8MAX()It returns the maximum value.9MIN()It returns the minimum value.10ST()It returns the population standard deviation.11STDDEV()It returns the population standard deviation.12STDDEV_POP()It returns the population standard deviation.13STDDEV_SAMP()It returns the sample ... Read More
92 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 | YEAR(Doj) | count(*) | +-------------+-----------+----------+ | Prof | 2009 | 2 | | Asst.Prof | 2015 | 1 | | Asst.Prof | 2016 | 1 | | Prof ... Read More
219 Views
As we know that SOUNDEX() function is used to return the soundex, a phonetic algorithm for indexing names after English pronunciation of sound, a string of a string. In the following example, we are taking the data from ‘student_info’ table and applying SOUNDEX() function with LIKE operator to retrieve a particular record from a table −mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla ... Read More
164 Views
In such kind of cases when a stored function got NULL values then it will return NULL as the result. It can be understood from the example below in which we have a NULL value in the records of student ‘Mohit’. Now, when we will apply the stored function ‘avg_marks’ on this data, it will return NULL as result.mysql> Select * from Student_marks; +-------+------+---------+---------+---------+ | Name | Math | English | Science | History | +-------+------+---------+---------+---------+ | Raman | 95 | 89 | 85 | 81 | | Rahul | 90 | ... Read More
332 Views
MySQL Stored functions can reference tables but they cannot make use of statements that return a result set. Hence we can say that there is no SELECT query that returns result set. But we can have SELECT INTO to get rid of that. For example, we are creating a function ‘Avg_marks’ that uses the dynamic data from table named ‘Student_marks’, having following records, to calculate the average of marks.mysql> Select * from Student_marks; +-------+------+---------+---------+---------+ | Name | Math | English | Science | History | +-------+------+---------+---------+---------+ | Raman | 95 | 89 | 85 | ... Read More
282 Views
With the help of SHOW CREATE FUNCTION statement, we can see the source code of a stored function. To make it understand we are using the stored function named Hello() in the query as follows −mysql> SHOW CREATE FUNCTION Hello\G *************************** 1. row *************************** Function: Hello sql_mode: ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION Create Function: CREATE DEFINER=`root`@`localhost` FUNCTION `Hello`(S Varchar(20)) RETURNS varchar(20) CHARSET latin1 DETERMINISTIC RETURN CONCAT('Hello, ', S, '!') character_set_client: cp850 collation_connection: cp850_general_ci Database Collation: latin1_swedish_ci 1 row in set (0.00 sec)Read More
72 Views
We can mysql.proc to see the list, along with complete information, of stored functions in a particular MySQL database by the following query −mysql> Select * from mysql.proc where db = 'query' AND type = 'FUNCTION' \G *************************** 1. row *************************** db: query name: factorial type: FUNCTION specific_name: factorial language: SQL sql_data_access: CONTAINS_SQL is_deterministic: YES security_type: DEFINER ... Read More
64 Views
We can see the list, along with other information, of stored functions in a particular MySQL database by the following query −mysql> SHOW FUNCTION STATUS WHERE db = 'query'\G *************************** 1. row *************************** Db: query Name: factorial Type: FUNCTION Definer: root@localhost Modified: 2021-11-16 14:04:48 Created: 2021-11-16 14:04:48 Security_type: DEFINER ... Read More
607 Views
As we know that with the help of QUOTE() function we can put the values of a column in single quotes. By using QUOTE() function with UPDATE clause we can update the table having quoted values. We need to give column name as the parameter of QUOTE() function. Following example will update the table ‘examination_btech’ after putting the values of column ‘Course’ in single quotes. Example mysql> UPDATE examination_btech SET Course = QUOTE(Course); Query OK, 10 rows affected (0.05 sec) mysql> Select * from examination_btech; +--------+----------+----------+ | RollNo | Name | Course ... Read More