AmitDiwan has Published 10740 Articles

Find percentage from marks in MySQL

AmitDiwan

AmitDiwan

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

593 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

750 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

328 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

222 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

305 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

292 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

252 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

MySQL query to fetch date more recent than 14 days?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:28:09

881 Views

Let us first create a −mysql> create table DemoTable1392    -> (    -> ArrivalDate  date    -> ); Query OK, 0 rows affected (0.43 sec)Insert some records in the table using insert −mysql> insert into DemoTable1392 values('2019-09-10'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable1392 values('2019-09-26'); ... Read More

Fix error in MySQL “select ClientId,ClientName,ClientAge, from tablename”

AmitDiwan

AmitDiwan

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

194 Views

The error occurs because we have a comma at the end of the column names, just before “from tablename’. Here is the error you may have got −mysql> select ClientId, ClientName, ClientAge, from DemoTable1391; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds ... Read More

MySQL automatic string to integer casting in WHERE clause to fetch a specific id

AmitDiwan

AmitDiwan

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

635 Views

If the string begins with integer then it converts the string to integer, otherwise it won’t. Let us first create a −mysql> create table DemoTable1390    -> (    -> StudentId varchar(20)    -> ); Query OK, 0 rows affected (0.93 sec)Insert some records in the table using insert −mysql> ... Read More

Advertisements