- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
303 Views
For this, you can use time_format(). Let us first create a table −mysql> create table DemoTable1326 -> ( -> Arrivaltime time -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1326 values('12:10:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1326 values('20:00:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1326 values('22:45:55'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1326 values('04:10:24'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * ... Read More
93 Views
To order MySQL results without identifier, the syntax is as follows −select * from yourTableName order by 1 DESC LIMIT yourLimitValue;Let us first create a table −mysql> create table DemoTable1325 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1325 values(100, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1325 values(101, 'Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1325 values(120, 'David'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More
1K+ Views
You can use aggregate function count(*). If it returns a value greater than 1, that would mean the table has composite primary key.Let us first create a table −mysql> create table DemoTable1324 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (0.52 sec)Here is the query to add composite primary key −mysql> alter table DemoTable1324 ADD CONSTRAINT constr_IdAgeCountry PRIMARY KEY (StudentId, StudentAge, StudentCountryName); Query OK, 0 rows affected (1.29 sec) Records: 0 Duplicates: 0 Warnings: 0Following is the query to identify composite ... Read More
195 Views
You can use the concept INFORMATION_SCHEMA.TABLES for this. Let us first create a table. This would be our most recent table −mysql> create table DemoTable1323 -> ( -> FirstName varchar(10) -> ); Query OK, 0 rows affected (0.43 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1323 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1323 values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1323 values('Bob'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable1323;This will produce ... Read More
83 Views
For this, use MySQL YEAR() as in the below syntax −select * from yourTableName where year(yourColumnName)=’yourYearValue’;Let us first create a table −mysql> create table DemoTable1322 -> ( -> DOB date -> ); Query OK, 0 rows affected (0.55 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1322 values('1999-04-12'); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1322 values('2010-12-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1322 values('2015-03-09'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1322 values('2007-05-24'); Query OK, 1 row affected (0.08 sec)Display all records from the table ... Read More
186 Views
To display the count, use aggregate function COUNT(*). Let us first create a table −mysql> create table DemoTable1321 -> ( -> ArrivalDatetime timestamp -> ); Query OK, 0 rows affected (0.50 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1321 values(now()); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1321 values('2019-01-10 12:34:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1321 values('2019-06-12 11:34:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1321 values('2019-06-12 04:50:00'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1321 values('2019-09-18 10:50:45'); Query OK, 1 ... Read More
92 Views
To display only the month number, use DATE_FORMAT() along with STR_TO_DATE(). Let us first create a table:mysql> create table DemoTable1320 -> ( -> MonthName varchar(20) -> ); Query OK, 0 rows affected (0.43 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1320 values('10/10/2010'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1320 values('11/12/2018'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1320 values('12/01/2019'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable1320;Output+------------+ | MonthName | +------------+ | 10/10/2010 | | 11/12/2018 | ... Read More
101 Views
To create a table from an already created table, use CREATE TABLE AS SELECT statement. Let us first create a table −mysql> create table DemoTable1318 -> ( -> Id int, -> FirstName varchar(10), -> LastName varchar(10), -> Age int -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1318 values(1, 'Chris', 'Brown', 21); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1318 values(2, 'David', 'Miller', 24); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1318 values(3, 'Carol', 'Taylor', 23); Query OK, 1 row affected (0.11 ... Read More
275 Views
In MySQL, you can easily return multiple results, but also achieve this with subquery using IN(). Let us first create a table −mysql> create table DemoTable1317 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert commandmysql> insert into DemoTable1317(Name) values('Chris Brown'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1317(Name) values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1317(Name) values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1317(Name) values('John Smith'); ... Read More
231 Views
Let us first create a table −mysql> create table DemoTable1316 -> ( -> Value varchar(40) -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1316 values('MySQL'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1316 values('Java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1316 values('MongoDB'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1316 values('C++'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1316;This will produce the following output. These are the ... Read More