Reputation: 453
I made a view in SQL Management Studio and it is working fine but there is a problem when I search data by specific ID it shows more than one rows of the data.
Note: View is getting data from two tables and these tables contain one same ID column, Name of the same Column is "Reservation ID"
I have attached a picture of the scenario. Please guide me where i am making mistake.
Thanks
select Reservation.Reservation_ID
,Reservation.Customer_ID
,Reservation.Exact_Arrival
,Reservation.Exact_Departure,Reservation.Number_of_Persons
,Reservation.Room_Floor
,Reservation.Room_Number
,Reservation.Room_Type
,Reservation.Vehicle_Number
,CustomersDetails.Customer_Address
,CustomersDetails.Customer_CNIC
,CustomersDetails.Customer_Full_Name
,CustomersDetails.Customer_Phone_Number
from Reservation,CustomersDetails;
Upvotes: 0
Views: 65
Reputation: 123
Based on the comments you and I had, it appears that you need to build your view a little bit differently. You currently are dumping all the information back from both tables with no joins in place. Build you view as so,
create view [dbo].[V_Information]
As select Reservation.Reservation_ID,
Reservation.Customer_ID,
Reservation.Exact_Arrival,
Reservation.Exact_Departure,
Reservation.Number_of_Persons,
Reservation.Room_Floor,
Reservation.Room_Number,
Reservation.Room_Type,
Reservation.Vehicle_Number,
CustomersDetails.Customer_Address,
CustomersDetails.Customer_CNIC,
CustomersDetails.Customer_Full_Name,
CustomersDetails.Customer_Phone_Number
from
Reservation
INNER JOIN CustomersDetails
ON Reservations.Customer_ID = CustomerDetails.Customer_ID;
Upvotes: 3