Selecting from a MySQL table based on parts of a timestamp?

AmitDiwan
Updated on 03-Oct-2019 07:19:07

111 Views

Let us first create a table −mysql> create table DemoTable (    AdmissionDate timestamp ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2007-01-10'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('2015-07-12'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2017-11-01'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-08-29'); Query OK, 1 row affected (0.08 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------------+ | AdmissionDate ... Read More

MySQL query to fetch column length declared with BLOB type

AmitDiwan
Updated on 03-Oct-2019 07:16:58

254 Views

For this, use the LENGTH() function from MySQL. Let us first create a table. We have declared the type of column as BLOB −mysql> create table DemoTable (    Title blob ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('This is a MySQL tutorial'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Java is an object oriented programming language'); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable values('C is a procedural language'); Query OK, 1 row affected (0.20 sec)Display all records from ... Read More

How to swap a specific field value in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:14:13

69 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Number1 int,    Number2 int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Number1, Number2) values(10, 30); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Number1, Number2) values(60, 50); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Number1, Number2) values(110, 100); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

Searching 2 fields at the same time to fetch a specific First Name and Last Name from a table in MySQL

AmitDiwan
Updated on 03-Oct-2019 07:11:59

53 Views

For this, you can use LIKE operator along with AND. Let us first create a table −mysql> create table DemoTable (    EmployeeFirstName varchar(50),    EmployeeLastName varchar(50) ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'Smith'); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable values('David', 'Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Carol', ... Read More

Can we use “LIKE concat()” in a MySQL query?

AmitDiwan
Updated on 03-Oct-2019 07:09:22

5K+ Views

Yes, we can do that. Let us first create a table −mysql> create table DemoTable (    Name varchar(50) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

What is the usage of yield keyword in JavaScript?

usharani
Updated on 03-Oct-2019 07:08:09

127 Views

The yield keyword is used in JavaScript to pause and resume a generator function. The value of the expression is returned to the generator's caller.Here’s the syntax, where “exp” is the expression and the optional value is returned by “val”, which is passed to the generator's next() method.[val] = yield [exp];Here are the examples:function* displayRank () {    var selPlayers= [1, 2, 3, 4];    for (var a = 0; a < selPlayers.length; a++) {       yield selPlayers[i];    } }After defining a generator function, use it like the following.Here displayRank() is the generator function:var rank = displayRank(); ... Read More

How to turn a String into a JavaScript function call?

Smita Kapse
Updated on 03-Oct-2019 07:00:23

335 Views

To turn a string into a JavaScript function call, try to run the following codeExampleLive Demo                    function myFunction(argument) {             alert('My function ' + argument);          }          functionName = 'myFunction';          window[functionName]('is working.');          

MySQL query to select a random row value (Id and Name) having multiple occurrences (Name)?

AmitDiwan
Updated on 03-Oct-2019 07:00:00

412 Views

For this, use RAND() for random records and LIMIT 1 to get only a single value. However, use the WHERE clause to select that particular ‘Name’, which is repeating.Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20) ); Query OK, 0 rows affected (1.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected ... Read More

Update only a single column in a MySQL table and increment on the basis of a condition

AmitDiwan
Updated on 03-Oct-2019 06:56:39

79 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(50),    Score int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam', 45); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Mike', 28); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('Carol', 27); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David', 67); 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 ... Read More

MySQL time period query to fetch date records from interval of 14 weeks from current date?

AmitDiwan
Updated on 03-Oct-2019 06:54:26

178 Views

For this, you can use the BETWEEN keyword. Let us first create a table −mysql> create table DemoTable (    ArrivalDate date ); Query OK, 0 rows affected (0.93 sec)Let’s say the current date is 2019-08-31.Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-03-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-09-01'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-08-31'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-06-30'); Query OK, 1 ... Read More

Advertisements