0% found this document useful (0 votes)
5 views3 pages

Ip SQL Hotel Customer

The document outlines the creation of a MySQL database named 'class12ip2024' with tables for hotels and customers, including their attributes and relationships. It provides SQL commands for inserting data into these tables and executing various queries to retrieve information about hotels and their customers. The queries demonstrate how to join the tables and filter results based on specific criteria.

Uploaded by

rihanais12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Ip SQL Hotel Customer

The document outlines the creation of a MySQL database named 'class12ip2024' with tables for hotels and customers, including their attributes and relationships. It provides SQL commands for inserting data into these tables and executing various queries to retrieve information about hotels and their customers. The queries demonstrate how to join the tables and filter results based on specific criteria.

Uploaded by

rihanais12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL JOIN

mysql> create database class12ip2024;


Query OK, 1 row affected (0.00 sec)

mysql> use class12ip2024;


Database changed
mysql> create table hotel
-> (hno int not null primary key,
-> hname varchar(20),
-> city varchar(10),
-> phone int not null unique,
-> rating int default 3,
-> rates int check(rates>=100 and rates<=1000)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> create table customer


-> ( custid int(5) not null primary key,
-> custname varchar(20),
-> contact int(15),
-> chkin date,
-> chkout date,
-> hno int,
-> foreign key(hno) references hotel (hno));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into hotel values(101,'Atlantis The Palm', 'Dubai',


4567898,7.2,2240);
mysql> insert into hotel values(102,'Burj Al Arab', 'Dubai',
4455666,9,4895);

mysql> insert into customer values(1001, 'Saumya',6767760, '2019-11-11',


'2019-11-20',101);
mysql> insert into customer values(1002, 'Akshaya',4455445, '2022-07-10',
'2022-07-15',105);

mysql> select * from hotel;


+-----+--------------------+-----------+---------+--------+-------+
| hno | hname | city | phone | rating | rates |
+-----+--------------------+-----------+---------+--------+-------+
| 101 | Atlantis The Palm | Dubai | 4567898 | 7 | 2240 |
| 102 | Burj Al Arab | Dubai | 4455666 | 9 | 4895 |
| 103 | Raha Beach Hotel | Dubai | 4242444 | 6 | 1103 |
| 104 | Emirates Pal Hotel | Abu Dhabi | 6767600 | 8 | 2370 |
| 105 | Al Ain Hotel | Al Ain | 5567000 | 9 | 311 |
| 106 | Raha Beach Hotel | Abu Dhabi | 6767676 | 5 | 400 |
| 107 | Bab Al Bahr | Ajman | 8822222 | 7 | 560 |
| 108 | Yas Hotel | Abu Dhabi | 6770000 | 7 | 1325 |
| 109 | Bab Al Bahr | Abu Dhabi | 6622222 | 7 | 560 |
+-----+--------------------+-----------+---------+--------+-------+
9 rows in set (0.00 sec)
mysql> select * from customer;
+--------+----------+---------+------------+------------+------+
| custid | custname | contact | chkin | chkout | hno |
+--------+----------+---------+------------+------------+------+
| 1001 | Saumya | 6767760 | 2019-11-11 | 2019-11-20 | 101 |
| 1002 | Akshaya | 4455445 | 2022-07-10 | 2022-07-15 | 105 |
| 1003 | Vanessa | 6626662 | 2022-04-11 | 2022-04-15 | 106 |
| 1004 | Sanjana | 6445544 | 2023-05-10 | 2023-05-20 | 105 |
| 1005 | Sunaina | 6777710 | 2023-06-11 | 2023-06-15 | 101 |
+--------+----------+---------+------------+------------+------+
5 rows in set (0.00 sec)

Q 1: Display hotel number, name, phone along with customer


name and number
mysql> select hotel.hno,hname,phone,custname,contact from hotel,customer
where hotel.hno=customer.hno;

Q 2: Display hotel number, name, phone along with guest name


and contact numbers of hotels in Dubai and Ajman.
mysql> select hotel.hno,hname,phone,custname,contact from hotel,customer
where hotel.hno=customer.hno and city IN('Dubai','Ajman');
+-----+-------------------+---------+----------+---------+
| hno | hname | phone | custname | contact |
+-----+-------------------+---------+----------+---------+
| 101 | Atlantis The Palm | 4567898 | Saumya | 6767760 |
| 101 | Atlantis The Palm | 4567898 | Sunaina | 6777710 |
+-----+-------------------+---------+----------+---------+
2 rows in set (0.00 sec)

Q 3: Display hotel number, guest name in alphabetical order of


hotels and for each hotel in alphabetical order of guest name.
mysql> select hotel.hno,hname,custname from hotel,customer where
hotel.hno=customer.hno order by custname,hname;
+-----+-------------------+----------+
| hno | hname | custname |
+-----+-------------------+----------+
| 105 | Al Ain Hotel | Akshaya |
| 105 | Al Ain Hotel | Sanjana |
| 101 | Atlantis The Palm | Saumya |
| 101 | Atlantis The Palm | Sunaina |
| 106 | Raha Beach Hotel | Vanessa |
+-----+-------------------+----------+
5 rows in set (0.01 sec)

Q 4: Display guest name, check in date, hotel name and guest


phone number who checked out for those guests who checked in,
in the month of April.
mysql> select custname,chkin,hname,contact from hotel,customer where
hotel.hno=customer.hno and Month(chkout)=04;
+----------+------------+------------------+---------+
| custname | chkin | hname | contact |
+----------+------------+------------------+---------+
| Vanessa | 2022-04-11 | Raha Beach Hotel | 6626662 |
+----------+------------+------------------+---------+
1 row in set (0.00 sec)

You might also like