Articles on Trending Technologies

Technical articles with clear explanations and examples

Exclude rows based on column value when another duplicate column value is found in MySQL?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 571 Views

For this, you can use subquery. Let us first create a −mysql> create table DemoTable1427    -> (    -> StudentId int,    -> StudentMarks int    -> ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert −mysql> insert into DemoTable1427 values(201, 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1427 values(201, 99); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1427 values(210, 98); Query OK, 1 row affected (0.16 sec)Display all records from the table using select −mysql> select * from DemoTable1427 ;This will produce the following output ...

Read More

How to simulate the LIMIT MySQL clause with an Access database?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 759 Views

In Microsoft Access, you can use TOP instead of LIMIT. Let us first create a −Insert some records in the table using insert command −Following is the query to simulate the LIMIT MySQL clause with an Access database −After clicking Run, you will get the desired output −In MySQL, to get top 5 values, you need to use LIMIT 5 −

Read More

MySQL query to order records but fix a specific name and display rest of the values (only some) random

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 145 Views

For this, you can use ORDER BY RAND() with LIMIT. Let us first create a −mysql> create table DemoTable1426    -> (    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert −mysql> insert into DemoTable1426 values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1426 values('Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1426 values('Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1426 values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1426 values('Sam'); Query OK, 1 row ...

Read More

Is it possible to combine 'DISTINCT' and 'COUNT' queries, so that I can see how many times each distinct value appears in a MySQL table column?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 228 Views

Yes, you can use aggregate function COUNT(*) along with GROUP BY clause. Let us first create a −mysql> create table DemoTable1425    -> (    -> JoiningYear int    -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert −mysql> insert into DemoTable1425 values(2000); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1425 values(2010); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1425 values(2015); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1425 values(2000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1425 values(2010); Query OK, ...

Read More

MySQL query to replace part of string before dot

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 382 Views

For this, use CONCAT() along with SUBSTRING_INDEX(). Let us first create a −mysql> create table DemoTable1424    -> (    -> Value varchar(60)    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert −mysql> insert into DemoTable1424 values('567.78483733'); Query OK, 1 row affected (0.78 sec) mysql> insert into DemoTable1424 values('1023.45252443'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1424 values('7893322.5635543434'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1424 values('90944.665665'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select −mysql> select * from DemoTable1424;This ...

Read More

Replace records based on conditions in MySQL?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 863 Views

To set conditions, use MySQL CASE statement. Let us first create a −mysql> create table DemoTable1481    -> (    -> PlayerScore int    -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert −mysql> insert into DemoTable1481 values(454); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable1481 values(765); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1481 values(890); Query OK, 1 row affected (0.09 sec)Display all records from the table using select −mysql> select * from DemoTable1481;This will produce the following output −+-------------+ | PlayerScore | +-------------+ |   ...

Read More

Can we fetch multiple values with MySQL WHERE Clause?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 303 Views

Yes, we can fetch, but use MySQL OR for conditions. Let us first create a −mysql> create table DemoTable1421    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert −mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('Chris', 10000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('Bob', 15000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('David', 8000); Query OK, 1 row affected (0.09 sec) mysql> insert ...

Read More

How to update multiple rows using single WHERE clause in MySQL?

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 980 Views

For this, you can use MySQL IN(). Let us first create a −mysql> create table DemoTable1420    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20),    -> LastName varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.12 sec)Insert some records in the table using insert −mysql> insert into DemoTable1420(FirstName, LastName, Age) values('Chris', 'Brown', 23); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1420(FirstName, LastName, Age) values('David', 'Miller', 22); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1420(FirstName, LastName, Age) values('John', 'Smith', 24); Query OK, ...

Read More

Convert MySQL time from HH:MM:SS to HH:MM

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 1K+ Views

To convert, use MySQL TIME_FORMAT(). Let us first create a −mysql> create table DemoTable1419    -> (    -> ArrivalTime time    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. Here, we have inserted time records −mysql> insert into DemoTable1419 values('12:30:45'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1419 values('11:00:55'); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable1419 values('09:59:34'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select −mysql> select * from DemoTable1419;This will produce the following output −+-------------+ | ...

Read More

Order date records and fetch the 2nd ordered record in MySQL

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 160 Views

To order, use ORDER BY and to fetch only the 2nd ordered record, use MySQL LIMIT and set offset as well. Let us first create a −mysql> create table DemoTable1417    -> (    -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CustomerName varchar(20),    -> ShippingDate date    -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert −mysql> insert into DemoTable1417(CustomerName, ShippingDate) values('Chris', '2019-01-21'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1417(CustomerName, ShippingDate) values('David', '2018-12-01'); Query OK, 1 row affected (0.55 sec) mysql> insert into DemoTable1417(CustomerName, ShippingDate) ...

Read More
Showing 56571–56580 of 61,297 articles
Advertisements