AmitDiwan has Published 10744 Articles

Why do backticks won’t work in the SET part of an UPDATE query (for MySQL)?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:48:35

184 Views

Backticks would work if written correctly as in the below syntax −update `yourTableName` set `yourTableName`.`yourColumnName`='yourNewValue' where yourCondition;Let us first create a −mysql> create table `DemoTable_1401`    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert −mysql> ... Read More

How to implement CANDIDATE key in any MySQL table?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:47:16

3K+ Views

Each relation may have one or more candidate key. One of these candidate keys is called Primary Key. Each candidate key qualifies for Primary Key. Therefore, candidates for Primary Key is called Candidate Key. To implement candidate key in MySQL, set more than one column as unique key. These keys ... Read More

Getting the next primary key without adding a new record is impossible, isn't it in MYSQL

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:45:43

81 Views

No, it is possible to get the next primary key without adding a new record. Let us first create a −mysql> create table DemoTable1399    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> PRIMARY KEY(StudentId)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records ... Read More

Find percentage from marks in MySQL

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:42:56

554 Views

Let us first create a −mysql> create table DemoTable1398    -> (    -> Marks int    -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert −mysql> insert into DemoTable1398 values(78); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1398 values(82); ... Read More

Comparison of varchar date records from the current date in MySQL

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:41:10

717 Views

For date comparison, you can use STR_TO_DATE(). Following is the syntax −select * from yourTableName where str_to_date(yourColumnName, 'yourFormatSpecifier') > curdate();Let us first create a −mysql> create table DemoTable1397    -> (    -> AdmissionDate varchar(40)    -> );s Query OK, 0 rows affected (0.97 sec)Insert some records in the table ... Read More

Concatenate all the columns in a single new column with MySQL

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:38:41

307 Views

Let us first create a −mysql> create table DemoTable1396    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(40),    -> Age int    -> ); Query OK, 0 rows affected (0.93 sec)Insert some records in the table using insert −mysql> insert into DemoTable1396(Name, ... Read More

Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:36:57

206 Views

Let us first create a −mysql> create table DemoTable1    -> (    -> Id int    -> ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert −mysql> insert into DemoTable1 values(1); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1 values(NULL); ... Read More

MySQL query to sort multiple columns together in a single query

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:34:53

280 Views

To sort multiple columns, use ORDER BY GREATEST(). Let us first create a −mysql> create table DemoTable1395    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert −mysql> ... Read More

Format amount values for thousands number with two decimal places in MySQL?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:32:35

267 Views

For thousands number, use MySQL FORMAT(). Let us first create a −mysql> create table DemoTable1394    -> (    -> Amount decimal(7, 3)    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert −mysql> insert into DemoTable1394 values(60); Query OK, 1 row affected ... Read More

MySQL pattern matching 3 or more “a's” in name?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:29:58

226 Views

Following is the syntax −select * from yourTableName where yourColumnName like '%a%a%a%';Let us first create a −mysql> create table DemoTable1393    -> (    -> CountryName varchar(40)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert −mysql> insert into DemoTable1393 values('andorra'); Query ... Read More

Advertisements