MySQL GROUP BY & HAVING
How to use Group By clause In MySql Tables:
With Inner Join Syntax:
Code:
CREATE TABLE personal(
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
percentage INT NOT NULL,
age INT NOT NULL,
gender VARCHAR(1) NOT NULL,
city INT NOT NULL,
courses INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (city) REFERENCES City (cid),
FOREIGN KEY (courses) REFERENCES Courses (course_id)
);
INSERT INTO personal(id,name,percentage,age,gender,city,courses)
VALUES
(1,"Aqib","45","13","M",1,1),
(2,"Khadija","56","21","F",2,2),
(3,"Salman Khan","62","20","M",1,1),
(4,"Aqeela","47","18","F",3,1),
(5,"Saqib","74","22","M",1,3),
(6,"Abraham","64","21","M",2,2),
(7,"Shahid","52","20","M",1,3);
create table "city" and insert records
CREATE TABLE city( cid INT NOT NULL AUTO_INCREMENT, cityname VARCHAR(50) NOT NULL, PRIMARY KEY (cid) );
insert records in "city" tableINSERT INTO city(cityname)
VALUES('Mul'),
('Lhr'),
('Mul'),
('Bhw'),
('Mul');
CREATE TABLE personal(
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
percentage INT NOT NULL,
age INT NOT NULL,
gender VARCHAR(1) NOT NULL,
city INT NOT NULL,
courses INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (city) REFERENCES City (cid),
FOREIGN KEY (courses) REFERENCES Courses (course_id)
);
INSERT INTO personal(id,name,percentage,age,gender,city,courses)
VALUES
(1,"Aqib","45","13","M",1,1),
(2,"Khadija","56","21","F",2,2),
(3,"Salman Khan","62","20","M",1,1),
(4,"Aqeela","47","18","F",3,1),
(5,"Saqib","74","22","M",1,3),
(6,"Abraham","64","21","M",2,2),
(7,"Shahid","52","20","M",1,3);
create table "city" and insert records
CREATE TABLE city( cid INT NOT NULL AUTO_INCREMENT, cityname VARCHAR(50) NOT NULL, PRIMARY KEY (cid) );
insert records in "city" tableINSERT INTO city(cityname)
VALUES('Mul'),
('Lhr'),
('Mul'),
('Bhw'),
('Mul');
create table "courses" and insert records
GROUP BY
How to work Having command in mySql Tables:
Comments
Post a Comment