Fetching records from a table with NULL and other values on the basis of conditions in MySQL

AmitDiwan
Updated on 30-Sep-2019 07:12:36

81 Views

Let us first create a table −mysql> create table DemoTable (    value1 int,    value2 int,    value3 int ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20, 40, null); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(40, 40, null); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(null, null, null); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+--------+--------+ | value1 | value2 ... Read More

MySQL query to ORDER BY records on the basis of modulus result

AmitDiwan
Updated on 30-Sep-2019 07:08:44

84 Views

For this, use ORDER BY with a modulus operator. Let us first create a table −mysql> create table DemoTable (    StudentId int,    StudentName varchar(100) ); Query OK, 0 rows affected (1.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(101, 'Robert'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.23 sec)Display all records from the table using ... Read More

What is the difference between JavaScript and C++?

Sreemaha
Updated on 30-Sep-2019 07:06:17

2K+ Views

The following are the differences between JavaScript and C++.JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complementary to and integrated with Java. JavaScript is very easy to implement because it is integrated with HTML. It is open and cross-platform.C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.JavaScript is a scripting whereas C++ is a programming language.C++ program is to be compiled and executed, whereas a script in ... Read More

MySQL multiple COUNT with multiple columns?

AmitDiwan
Updated on 30-Sep-2019 07:05:35

266 Views

You can use an aggregate function SUM() along with IF(). Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (2.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('John', 'Smith'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (1.38 sec) mysql> insert into DemoTable values('Bob', 'Doe'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Sam', ... Read More

Use LIKE % to fetch multiple values in a single MySQL query

AmitDiwan
Updated on 30-Sep-2019 07:00:04

3K+ Views

To fetch multiple values wit LIKE, use the LIKE operator along with OR operator. Let us first create a table −mysql> create table DemoTable1027 (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (1.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1027 values(100, 'John'); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable1027 values(20, 'Chris'); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable1027 values(200, 'Robert'); Query OK, 1 row affected (0.84 sec) mysql> insert into DemoTable1027 values(400, 'Mike'); Query OK, 1 row affected (0.47 sec)Display all ... Read More

What does the leading semicolon in JavaScript libraries do?

mkotla
Updated on 30-Sep-2019 06:59:03

206 Views

A function in JavaScript looks like the following:(function(){...})()A library in JavaScript shows a function, which begins with a semicolon, for example:;(function ) { }The semicolon allows to safely concatenate several JS files into one. This is to serve it faster as one HTTP request.A leading semicolon can also be to protect from preceding code, which may have been improperly closed. A semicolon will definitely prevent this from happening.

What is the difference between a method and a function?

seetha
Updated on 30-Sep-2019 06:57:27

6K+ Views

Method and a function are the same, with different terms. A method is a procedure or function in object-oriented programming.A function is a group of reusable code which can be called anywhere in your program. This eliminates the need for writing the same code again and again. It helps programmers in writing modular codes.The following is the syntax of a JavaScript function:     Here’s an example:    

MySQL select query to fetch data with null value?

AmitDiwan
Updated on 30-Sep-2019 06:57:06

376 Views

Let us first create a table −mysql> create table DemoTable (    CustomerName varchar(100),    CustomerCountryName varchar(100) ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Carol', NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', 'AUS'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Mike', NULL); Query OK, 1 row affected (0.18 sec)Display all records ... Read More

Show column value twice in MySQL Select?

AmitDiwan
Updated on 30-Sep-2019 06:54:42

203 Views

You can use concat(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(100); Query ... Read More

Get count of zeros for columns values declared with INT type in MySQL

AmitDiwan
Updated on 30-Sep-2019 06:52:26

171 Views

For this, you can use LENGTH() along with REPLACE(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10002000); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(00000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(400560); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------+ | Value    | +----------+ | 10002000 ... Read More

Advertisements