Suppose in our ‘Employee’ table we are having NULL as the value of ‘salary’ column for two employees. The data, shown as follows, is itself not meaningful. , We can avoid displaying NULL in the output by using the IF() function to return ‘N/A’ instead of NULL. ,
When we use RAND() function along with both ORDER BY and LIMIT clause in a query, MySQL returns the different set of rows or values each time. To understand it considers a table ‘Employee’ having the following records: , Now, the query below will use RAND() function with both ORDER BY and LIMIT clause in a query return randomly different set of values or rows: , It can be observ.....
When we use FIND_IN_SET() function in WHERE clause then it searches the search string within the given string as specified in the argument and retrieves all the columns from concerned rows. Following is an example to demonstrate it: In this example, we are getting the columns from ‘Student’ table where the rows have the value of name as ‘Gaurav’. Here the FIND_IN_SET.....
Both the functions are string functions and return the number of characters present in the string. But they differ in the concept that CHAR_LENGTH() function measures the string length in ‘characters’ whereas LENGTH() function measures the string length in ‘bytes’. In other words, we can say that CHAR_LENGTH() function is multi-byte safe i.e. it ignores whether the c.....
Followings are the ways in which we can write a query that returns only records that matches multiple conditions on the same column: As we know that MySQL ‘OR’ operator compares two expressions and returns TRUE if either of the expression is TRUE. Following example demonstrate that how we can use ‘OR’ operator for multiple conditions on the same column: , WHERE IN(&h.....
CREATE command is a DDL command which is used to create a table or a database. The syntax for creating table and database with CREATE command is as follows: The syntax for creating a database: , , In the example above we have created a database named ‘query’. The syntax for creating a table: , , In the example above, we have created a table named ‘Employee’ having tw.....
The following table will provide us the differences between PRIMARY KEY and UNIQUE constraint: PRIMARY KEYUNIQUE Constraint1. Only one Primary key can be created on a table.1. More than one UNIQUE Constraints can be added to a table.2. Primary key creates clustered index by default.2. UNIQUE Constraint creates a non-clustered index by default.3. We cannot insert null values in the column wh.....
As we know that AUTO_INCREMENT column must have the PRIMARY KEY constraint on it also hence when we will try to drop PRIMARY KEY constraint from the AUTO_INCREMENT column the MySQL returns an error message regarding the incorrect table definition. The example below will demonstrate it: Suppose we have ‘Accounts’ table having the following description: , It is having a file.....
Sign up now to get your own personalized profile!
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more