Check for NULL in a MySQL Query

Kumar Varma
Updated on 20-Jun-2020 13:03:23

276 Views

With the help of IS NULL operator, we can check for NULL in a MySQL query. We cannot use = (comparison operator) because as we know that NULL is not a value. Following example using the data from ‘employee’ table will exhibit it −Examplemysql> Select * from Employee WHERE Salary IS NULL; +----+-------+--------+ | ID | Name  | Salary | +----+-------+--------+ | 7  | Aryan | NULL   | | 8  | Vinay | NULL   | +----+-------+--------+ 2 rows in set (0.00 sec)The query above use IS NULL operator and produces the output where salary column is having NULL.mysql> ... Read More

Use RAND Function in ORDER BY Clause to Shuffle MySQL Rows

Paul Richard
Updated on 20-Jun-2020 13:02:41

457 Views

When we use MySQL ORDER BY clause with RAND() function then the result set would have the shuffled set of rows. In other words, the result set would be in a random order. To understand it considers a table ‘Employee’ having the following records −mysql> Select * from employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | | 6  | Mohan  | ... Read More

Generate Same Sequence of Random Numbers in MySQL

Vikyath Ram
Updated on 20-Jun-2020 13:01:46

273 Views

When invoked with an integer argument, RAND( ) uses that value to seed the random number generator. Each time you seed the generator with a given value, RAND( ) will produce the same sequence of random numbers. Following example will demonstrate it −Examplemysql> Select RAND(1), RAND(1), Rand(1); +---------------------+---------------------+---------------------+ | RAND(1)             | RAND(1)             | Rand(1)             | +---------------------+---------------------+---------------------+ | 0.40540353712197724 | 0.40540353712197724 | 0.40540353712197724 | +---------------------+---------------------+---------------------+ 1 row in set (0.00 sec)

Use IFNULL Function Instead of COALESCE in MySQL

karthikeya Boyini
Updated on 20-Jun-2020 13:00:17

2K+ Views

As we know that IFNULL() function will return the first argument if it is not NULL otherwise it returns the second argument. On the other hand, COALESCE() function will return first non-NULL argument. Actually, both IFNULL() and COALESCE() functions in MySQL works equivalently if the number of arguments is two only. The reason behind this is that IFNULL() function accepts only two arguments and in contrast, COALESCSE() function can accept any number of arguments.Suppose if we want to use IFNULL() function at the place of COALESCE() function then the number of arguments must be two. Following example will demonstrate it ... Read More

Check MySQL Tables in a Different Database Using IN Operator

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

123 Views

It can be done with the SHOW FULL TABLES statement. Its Syntax would be as follows −SyntaxSHOW FULL TABLES IN db_nameHere db_name is the name of the database from which we want to see the list of tables.ExampleWe are currently using the database named ‘query’ and the MySQL query below will show us the list of tables along with table type from the database named mysql.mysql> SHOW FULL TABLES IN mysql; +---------------------------+------------+ | Tables_in_mysql           | Table_type | +---------------------------+------------+ | arena                     | BASE TABLE | | ... Read More

Insert Value in Column Using MySQL COALESCE Function

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

845 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  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | NULL   | | 6  | Mohan  | NULL   | +----+--------+--------+ 6 rows in set (0.00 sec)Now, the following queries will use COALESCE() function along with UPDATE and ... Read More

Difference Between Class and Object in C#

karthikeya Boyini
Updated on 20-Jun-2020 12:58:55

325 Views

When you define a class, you define a blueprint for a data type.Objects are instances of a class. The methods and variables that constitute a class are called members of the class.To access the class members, you use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member for example, Box Box1 = new Box();Above you can see Box1 is our object. We will use it to access the members −Box1.height = 7.0;You can also use it to call member functions −Box1.getVolume();The following is an example showing ... Read More

Check MySQL Tables in Current Database with Table Type

V Jyothi
Updated on 20-Jun-2020 12:58:01

129 Views

It can be done with the SHOW FULL TABLES statement. Its Syntax would be as follows −SyntaxSHOW FULL TABLESExampleIn the following example our current database is ‘query’ hence the statement below will show us the table list along with table type in the result set from this database −mysql> SHOW FULL TABLES; +-----------------------------+------------+ | Tables_in_query             | Table_type | +-----------------------------+------------+ | accounts                    | BASE TABLE | | address                     | BASE TABLE | | cars     ... Read More

Differences Between Constructors and Destructors in C#

Ankith Reddy
Updated on 20-Jun-2020 12:57:24

541 Views

ConstructorsA class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor has exactly the same name as that of class and it does not have any return type.Constructor has the same name as the class name −class Demo {    public Demo() {} }The following is an example −Example Live Demousing System; namespace LineApplication {    class Line {       private double length; // Length of a line       public Line() {          Console.WriteLine("Object is being created");   ... Read More

Check MySQL Tables in a Different Database

vanithasree
Updated on 20-Jun-2020 12:57:10

104 Views

It can be done with the SHOW FULL TABLES statement. Its Syntax would be as follows −SyntaxSHOW FULL TABLES FROM db_nameHere, db_name is the name of the database from which we want to see the list of tables.ExampleWe are currently using the database named ‘query’ and the MySQL query below will show us the list of tables along with table type from the database named mysql.mysql> SHOW FULL TABLES FROM mysql; +---------------------------+------------+ | Tables_in_mysql           | Table_type | +---------------------------+------------+ | arena                     | BASE TABLE | | ... Read More

Advertisements