CREATE TABLE CRICKET (
  PLAYER_ID INTEGER PRIMARY KEY,
  player_name TEXT NOT NULL,
  player_stats TEXT NOT NULL,
  age INTEGER,
  mobile_number bigint,
  country TEXT
);
INSERT INTO CRICKET (PLAYER_ID, player_name, player_stats, age, mobile_number, country) VALUES
(1, 'Virat Kohli', 'Batsman', 32, '1234567890', 'India'),
(2, 'Rohit Sharma', 'Batsman', 34, '9876543210', 'India'),
(3, 'Steve Smith', 'Batsman', 31, '9876543211', 'Australia'),
(4, 'Kane Williamson', 'Batsman', 30, '9876543212', 'New Zealand'),
(5, 'Joe Root', 'Batsman', 30, '9876543213', 'England'),
(6, 'Babar Azam', 'Batsman', 27, '9876543214', 'Pakistan'),
(7, 'David Warner', 'Batsman', 35, '9876543215', 'Australia'),
(8, 'KL Rahul', 'Batsman', 29, '9876543216', 'India'),
(9, 'Aaron Finch', 'Batsman', 34, '9876543217', 'Australia'),
(10, 'Quinton de Kock', 'Batsman', 28, '9876543218', 'South Africa'),
(11, 'Shikhar Dhawan', 'Batsman', 35, '9876543219', 'India'),
(12, 'Faf du Plessis', 'Batsman', 37, '9876543220', 'South Africa'),
(13, 'AB de Villiers', 'Batsman', 36, '9876543221', 'South Africa'),
(14, 'Ross Taylor', 'Batsman', 37, '9876543222', 'New Zealand'),
(15, 'Eoin Morgan', 'Batsman', 35, '9876543223', 'England'),
(16, 'Ben Stokes', 'All-rounder', 30, '9876543224', 'England'),
(17, 'Shakib Al Hasan', 'All-rounder', 34, '9876543225', 'Bangladesh'),
(18, 'Hardik Pandya', 'All-rounder', 28, '9876543226', 'India'),
(19, 'Ravindra Jadeja', 'All-rounder', 32, '9876543227', 'India'),
(20, 'Jason Holder', 'All-rounder', 29, '9876543228', 'West Indies'),
(21, 'Chris Woakes', 'All-rounder', 32, '9876543229', 'England'),
(22, 'Andre Russell', 'All-rounder', 33, '9876543230', 'West Indies'),
(23, 'Shane Watson', 'All-rounder', 40, '9876543231', 'Australia'),
(24, 'Chris Gayle', 'All-rounder', 41, '9876543232', 'West Indies'),
(25, 'Dwayne Bravo', 'All-rounder', 37, '9876543233', 'West Indies'),
(26, 'Angelo Mathews', 'All-rounder', 34, '9876543234', 'Sri Lanka'),
(27, 'Nitish Kumar Reddy', 'All-rounder', 28, '9876543235', 'India'),
(28, 'Sunil Narine', 'All-rounder', 34, '9876543236', 'West Indies'),
(29, 'Ravichandran Ashwin', 'All-rounder', 32, '9876543237', 'India'),
(30, 'Romario Shephard', 'All-rounder', 30, '9876543238', 'West Indies'),
(31, 'Jasprit Bumrah', 'Bowler', 28, '9876543239', 'India'),
(32, 'Kagiso Rabada', 'Bowler', 26, '9876543240', 'South Africa'),
(33, 'Trent Boult', 'Bowler', 32, '9876543241', 'New Zealand'),
(34, 'Pat Cummins', 'Bowler', 28, '9876543242', 'Australia'),
(35, 'Mitchell Starc', 'Bowler', 31, '9876543243', 'Australia'),
(36, 'Rashid Khan', 'Bowler', 23, '9876543244', 'Afghanistan'),
(37, 'Mohammed Shami', 'Bowler', 30, '9876543245', 'India'),
(38, 'Imran Tahir', 'Bowler', 42, '9876543246', 'South Africa'),
(39, 'Kuldeep Yadav', 'Bowler', 26, '9876543247', 'India'),
(40, 'Mitchell Johnson', 'Bowler', 39, '9876543248', 'Australia'),
(41, 'Adam Zampa', 'Bowler', 28, '9876543249', 'Australia'),
(42, 'Mohammed Siraj', 'Bowler', 32, '9876543250', 'India'),
(43, 'Zaheer Khan', 'Bowler', 32, '9876543251', 'India'),
(44, 'Tushar Deshpande', 'Bowler', 28, '9876543252', 'India'),
(45, 'Kane Richardson', 'Bowler', 30, '9876543253', 'Australia');
select * from CRICKET;

CREATE TABLE coaches (
    COACH_ID INT,
    COACH_NAME TEXT,
    COACH_STATS TEXT,
    MOBILE_NUMBER bigint,
    country_name TEXT
);
INSERT INTO coaches (COACH_ID, COACH_NAME, COACH_STATS, MOBILE_NUMBER,country_name) VALUES
    (1, 'John Smith', 'Batsman', '1234567890','USA'),
    (2, 'Emily Johnson', 'All-rounder', '9876543210','USA'),
    (3, 'Michael Brown', 'Bowler', '4567890123','England'),
    (4, 'Sarah White', 'Batsman', '7890123456','Australia'),
    (5, 'David Wilson', 'All-rounder', '2345678901','England'),
    (6, 'Jessica Lee', 'Bowler', '5678901234','Australia'),
    (7, 'Chris Martinez', 'Batsman', '8901234567','USA'),
    (8, 'Jennifer Taylor', 'All-rounder', '3456789012','USA'),
    (9, 'Kevin Rodriguez', 'Bowler', '1234567890','England'),
    (10, 'Amanda Nguyen', 'Batsman', '6789012345','USA'),
    (11, 'Daniel Garcia', 'All-rounder', '9012345678','Spain'),
    (12, 'Megan Scott', 'Bowler', '4321098765','Australia'),
    (13, 'Robert Adams', 'Batsman', '2109876543','USA'),
    (14, 'Lauren Thomas', 'All-rounder', '5432109876','England'),
    (15, 'Brian Hall', 'Bowler', '8765432109','USA');
SELECT * FROM coaches;

CREATE TABLE teams (
    TEAM_ID INT,
    TEAM_NAME TEXT,
    COACH_NAME TEXT
);
INSERT INTO teams (TEAM_ID, TEAM_NAME, COACH_NAME) VALUES
    (1, 'MI', 'John Smith'),
    (2, 'CSK', 'Emily Johnson'),
    (3, 'SRH', 'Michael Brown'),
    (4, 'RR', 'Sarah White'),
    (5, 'KKR', 'David Wilson');
SELECT * FROM teams;

CREATE TABLE matches (
    MATCH_NAME TEXT,
    dates DATE
);
INSERT INTO matches (MATCH_NAME, dates) VALUES
    ('IPL', '2024-03-18'),
    ('BBL', '2024-04-07'),
    ('SA20', '2024-04-15');
SELECT * FROM matches;

SELECT COACH_NAME, player_name 
 FROM coaches, CRICKET
where COACH_NAME = 'Daniel Garcia' and player_stats = 'All-rounder';











 
by

MySQL online editor

Write, Run & Share MySQL queries online using OneCompiler's MySQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MySQL. Getting started with the OneCompiler's MySQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MySQL' and start writing queries to learn and test online without worrying about tedious process of installation.

About MySQL

MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.

Key Features:

  • Open-source relational database management systems.
  • Reliable, very fast and easy to use database server.
  • Works on client-server model.
  • Highly Secure and Scalable
  • High Performance
  • High productivity as it uses stored procedures, triggers, views to write a highly productive code.
  • Supports large databases efficiently.
  • Supports many operating systems like Linux*,CentOS*, Solaris*,Ubuntu*,Windows*, MacOS*,FreeBSD* and others.

Syntax help

Commands

1. CREATE

CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

Example

CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

2. ALTER

ALTER TABLE Table_name ADD column_name datatype;

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');

3. TRUNCATE

TRUNCATE table table_name;

4. DROP

DROP TABLE table_name;

5. RENAME

RENAME TABLE table_name1 to new_table_name1; 

6. COMMENT

Single-Line Comments:

 --Line1;

Multi-Line comments:

   /* Line1,
   Line2 */

DML Commands

1. INSERT

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

Note: Column names are optional.

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');

2. SELECT

SELECT column1, column2, ...
FROM table_name
[where condition]; 

Example

SELECT * FROM EMPLOYEE where dept ='sales';

3. UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Example

UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001'; 

4. DELETE

DELETE FROM table_name where condition;

Example

DELETE from EMPLOYEE where empId='0001'; 

Indexes

1. CREATE INDEX

  CREATE INDEX index_name on table_name(column_name);
  • To Create Unique index:
  CREATE UNIQUE INDEX index_name on table_name(column_name);

2. DROP INDEX

DROP INDEX index_name ON table_name;

Views

1. Create a View

Creating a View:
CREATE VIEW View_name AS 
Query;

2. How to call view

SELECT * FROM View_name;

3. Altering a View

ALTER View View_name AS 
Query;

4. Deleting a View

DROP VIEW View_name;

Triggers

1. Create a Trigger

CREATE TRIGGER trigger_name trigger_time trigger_event
    ON tbl_name FOR EACH ROW [trigger_order] trigger_body
/* where
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
trigger_order: { FOLLOWS | PRECEDES } */

2. Drop a Trigger

DROP TRIGGER [IF EXISTS] trigger_name;

Stored Procedures

1. Create a Stored Procedure

CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;

2. How to call Stored procedure

CALL sp_name;

3. How to delete stored procedure

DROP PROCEDURE sp_name;

Joins

1. INNER JOIN

SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;

2. LEFT JOIN

SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;

3. RIGHT JOIN

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;

4. CROSS JOIN

SELECT select_list from TABLE1 CROSS JOIN TABLE2;