Found 4378 Articles for MySQL

Display matching repeated date records only once in MySQL

AmitDiwan
Updated on 10-Dec-2019 05:56:12

88 Views

Let’s say we are finding records matching with the current date. Since we want repeated matching records only once, use LIMIT.For example, the current date is −2019-10-02Let us first create a table −mysql> create table DemoTable1450    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1450 values('2019-09-30'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1450 values('2019-10-02'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1450 values('2019-10-02'); Query OK, 1 row affected (0.10 sec) mysql> insert into ... Read More

Return maximum value from records in MySQL

AmitDiwan
Updated on 10-Dec-2019 05:53:12

145 Views

Let us first create a table −mysql> create table DemoTable1449    -> (    -> PlayerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> PlayerScore int    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1449(PlayerScore) values(1040); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1449(PlayerScore) values(1450); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1449(PlayerScore) values(1890); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable1449(PlayerScore) values(1650); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement ... Read More

Check if the current date falls in a given date range using MySQL query

AmitDiwan
Updated on 10-Dec-2019 05:50:53

725 Views

Let us first create a table −mysql> create table DemoTable1448    -> (    -> StartDate date,    -> EndDate date    -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1448 values('2019-01-21', '2019-03-22'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1448 values('2019-04-05', '2019-10-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1448 values('2019-10-01', '2019-10-29'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1448 values('2018-12-31', '2019-12-31'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> ... Read More

MySQL db query to fetch records from comma separate values on the basis of a specific value

AmitDiwan
Updated on 10-Dec-2019 05:47:04

127 Views

For this, you can use REGEXP in MySQL. Let’s say you want the row records wherein any of the comma separated value is 90. For this, use regular expression.Let us first create a table −mysql> create table DemoTable1447    -> (    -> Value varchar(100)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1447 values('19, 58, 90, 56'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1447 values('56, 89, 99, 100'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1447 values('75, 76, 65, ... Read More

Find the difference between current date and the date records from a MySQL table

AmitDiwan
Updated on 10-Dec-2019 05:44:06

275 Views

To find the difference, use the DATEDIFF() method. Let us first create a table −mysql> create table DemoTable1446    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (1.42 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1446 values('2019-01-21'); Query OK, 1 row affected (0.69 sec) mysql> insert into DemoTable1446 values('2019-02-01'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable1446 values('2019-09-30'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select * from DemoTable1446;This will produce the following output −+------------+ | DueDate ... Read More

Set conditions in a MySQL stored procedure

AmitDiwan
Updated on 10-Dec-2019 05:40:40

616 Views

To set conditions in a stored procedure, use IF...ELSE in MySQL. Following is the syntax for if-else −IF yourCondition then       yourStatement1,  ELSE           yourStatement2,  END IF;Let us implement the above syntax in a stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE IF_ELSE_DEMO(IN value int)    -> BEGIN    ->    SET @val=value;    ->    IF @val > 10 then    ->       select concat(@val, ' is greater than 10');    ->    ELSE    ->        select concat(@val, ' is less than 10 ');    ->    END ... Read More

How to get string as date in MySQL with dates as dot format specifier?

AmitDiwan
Updated on 10-Dec-2019 05:33:38

344 Views

To get string as date, use STR_TO_DATE() method. Let us first create a table −mysql> create table DemoTable1445    -> (    -> AdmissionDate varchar(20)    -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1445 values('01.10.2019'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1445 values('31.12.2018'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1445 values('01.02.2017'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select −mysql> select * from DemoTable1445;This will produce the following output −+---------------+ | AdmissionDate | ... Read More

Difference between SQL(Structured Query Language) and T-SQL(Transact-SQL).

Mahesh Parahar
Updated on 27-Nov-2019 07:58:51

552 Views

SQLSQL, Structured Query Language is a non-procedural language and is used by database engines to interpret SQL queries to create/modify/access the database elements.T-SQLT-SQL, Transact-SQL, is a procedural extension to SQL, used by SQL Server. It is similar to PL/SQL of Oracle.Following are the important difference between SQL and T-SQL.Sr. No.KeySQLT-SQL1TypeSQL is non-procedural by nature.T-SQL is procedural by natue.2MethodsSQL provides data manipulation and controlling functions.With T-SQL, we can write own procedures, functions with local variables.3ProprietarySQL is open to use and is common across RDBMS softwares.T-SQL is specific to SQL Server and is proprietary.4Query orderMultiple querires are submitted one by one.Using T-SQL, ... Read More

Difference between SQL and PL/SQL

Mahesh Parahar
Updated on 27-Nov-2019 07:32:03

14K+ Views

SQL, Structural Query Language is a standard database language which is used create, maintain and retrieve the relational database whereas PL/SQL, Procedural Language extension to SQL, it extends SQL and provide it procedural capabilities.Following are the important differences between SQL and PL/SQL.Sr. No.KeySQLPL/SQL1DefinitionSQL, is Structural Query Language for database.PL/SQL is a programming language using SQL for a database.2VariablesSQL has no variables.PL/SQL has variables, data types etc.3Control StructuresSQL has no FOR loop, if control and similar structures.PL/SQL has FOR loop, while loop, if controls and other similar structures.4OperationsSQL can execute a single operation at a time.PL/SQL can perform multiple operation at ... Read More

Difference between MySQL and MongoDB

Mahesh Parahar
Updated on 27-Nov-2019 07:27:28

702 Views

MySQL is a relational database. MongoDB is NoSQL Database.Following are the important differences between MySQL and MongoDB.Sr. No.KeyMySQLMongoDB1Owned/Developed ByMySQL is owned by Oracle.MongoDB is developed by MongoDB Inc.2Data StorageMySql stores data in tabular format as records in table.MongoDB stores records as documents.3LanguageSQL, Structured Query Language is used to query database.Dynamic Schema. Predefined structure is defined for incoming data.4Design ObjectivesNo efficient replication and Sharding available.High availability, Scalability, Replication and Sharding are inbuilt.5TermsMongoDB uses Collection, Document, Field, Embedded Document, Linking etc.MySQL uses Table, Row, Column, Joins etc.6Data StorageMySQL stores data in forms of records in table.MongoDB stores data in form of JSON ... Read More

Advertisements