Create Conditions in a MySQL Table with Multiple Columns

AmitDiwan
Updated on 22-Aug-2019 13:48:29

370 Views

For conditions, use IF(). Following is the syntax −IF(yourCondition, trueStatement, falseStatement);Let us first create a table −mysql> create table DemoTable612 (Number1 int, Number2 int, Score int); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable612 values(10, 20, 1000); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable612 values(30, 40, 500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable612 values(50, 70, 1200); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable612 values(100, 120, 400); Query OK, 1 row affected (0.16 sec)Display all records from ... Read More

Query Age from DOB in MySQL

AmitDiwan
Updated on 22-Aug-2019 13:15:13

318 Views

Let us first create a table −mysql> create table DemoTable611 (DOB date); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable611 values('1996-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable611 values('2001-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable611 values('2004-12-21'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable611 values('2000-02-03'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable611;This will produce the following output −+------------+ | DOB       | ... Read More

Top Occurring Entries in MySQL from a Table with Duplicate Values

AmitDiwan
Updated on 22-Aug-2019 13:13:01

132 Views

Let us first create a table −mysql> create table DemoTable610 (SubjectName varchar(100)); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable610 values('Java'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable610 values('MongoDB'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.08 sec) mysql> ... Read More

MySQL Query to Remove First Digit

AmitDiwan
Updated on 22-Aug-2019 13:05:05

797 Views

For this, use SUBSTR(). Following is the syntax −update yourTableName set yourColumnName=substr(yourColumnName, 2);Let us first create a table −mysql> create table DemoTable607 (Value varchar(100)); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable607 values('83967364'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable607 values('10939432'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable607 values('932111'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable607;This will produce the following output −+----------+ | Value    | +----------+ | 83967364 ... Read More

MySQL ORDER BY with EXPLAIN Command

AmitDiwan
Updated on 22-Aug-2019 13:02:12

160 Views

Let us first create a table −mysql> create table DemoTable606 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable606(FirstName) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable606(FirstName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable606(FirstName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable606(FirstName) values('David'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable606;This will produce the following output −+----+-----------+ ... Read More

HTML DOM Input Reset Form Property

AmitDiwan
Updated on 22-Aug-2019 12:59:34

253 Views

The HTML DOM Input Reset form property is used for returning the form reference that contains the given reset button. If the reset button is outside the form then it will simply return NULL. This property is read-only.SyntaxFollowing is the syntax for input Reset form property.resetObject.formExampleLet us look at an example for the Input Reset form property − Live Demo Input reset form Property UserName: Location: Get the form id by clicking on the below button GET FORM    function formId() {       var P=document.getElementById("RESET1").form.id;       ... Read More

Format Date to Display Month Names with the Entire Date in MySQL

AmitDiwan
Updated on 22-Aug-2019 12:57:43

152 Views

For this, you can use DATE_FORMAT(). Let us first create a table −mysql> create table DemoTable605 (DueDate date); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable605 values('2019-01-21'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable605 values('2019-02-23'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable605 values(curdate()); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable605;This will produce the following output −+------------+ | DueDate    | +------------+ | 2019-01-21 | | 2019-02-23 | | 2019-03-04 ... Read More

HTML DOM Input Reset Disabled Property

AmitDiwan
Updated on 22-Aug-2019 12:55:57

241 Views

The HTML DOM Input reset disabled property is used for setting or returning if the reset button should be disabled or not. It uses boolean values, with true representing the reset button should be disabled and false otherwise. The disabled property is set to false by default. The disabled element is greyed out by default and is unclickable.SyntaxFollowing is the syntax for −Setting the disabled property −resetObject.autofocus = true|falseHere, true=reset button is disabled and false=the reset button is not disabled. It is false by default.ExampleLet us look at an example for the Input reset disabled property − Live Demo ... Read More

HTML DOM Input Reset Autofocus Property

AmitDiwan
Updated on 22-Aug-2019 12:52:42

194 Views

The HTML DOM Input Reset autofocus property is associated with the HTML element’s autofocus attribute. This property is used for setting or returning if the reset button should be automatically focused when the page loads or not.SyntaxFollowing is the syntax for −Setting the autofocus property −resetObject.autofocus = true|falseHere, true represents that the reset button should get focus and false represents otherwise. It is set to false by default.ExampleLet us look at an example for the Input Reset autofocus property − Live Demo Reset Autofocus property UserName: Location: Get the reset ... Read More

Find the Name of a Column in MySQL

AmitDiwan
Updated on 22-Aug-2019 12:48:51

3K+ Views

For this, you can use SHOW COLUMNS or INFORMATION_SCHEMA.COLUMN.Let us first create a table −mysql> create table DemoTable603    (       ClientId int NOT NULL AUTO_INCREMENT,       ClientName varchar(100),       ClientAge int,       ClientAddress varchar(100),       ClientCountryName varchar(100),       ClientEducationDetails varchar(200),       PRIMARY KEY(ClientId)    ); Query OK, 0 rows affected (0.59 sec)CASE 1 − Using SHOW commandHere is the query to find the name of a column in MySQL −mysql> SHOW COLUMNS FROM DemoTable603;This will produce the following output −+------------------------+--------------+------+-----+---------+----------------+ | Field           ... Read More

Advertisements