Uniquedesign
Uniquedesign

Reputation: 453

How to show relevant data through SQL View

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. Scenerio of the problem

Thanks

select Reservation.Reservation_ID
      ,Reservation.Customer_ID
      ,Reservati‌​on.Exact_Arrival
      ,Res‌​ervation.Exact_Depar‌​ture,Reservation.Num‌​ber_of_Persons
      ,Reser‌​vation.Room_Floor
      ,Re‌​servation.Room_Numbe‌​r
      ,Reservation.Room_T‌​ype
      ,Reservation.Vehi‌​cle_Number
      ,Customers‌​Details.Customer_Add‌​ress
      ,CustomersDetail‌​s.Customer_CNIC
      ,Cust‌​omersDetails.Custome‌​r_Full_Name
      ,Customer‌​sDetails.Customer_Ph‌​one_Number 
from Reservation,CustomersDetails;

Upvotes: 0

Views: 65

Answers (1)

JJWillMC
JJWillMC

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,
Reservati‌​on.Exact_Arrival,
Res‌​ervation.Exact_Depar‌​ture,
Reservation.Num‌​ber_of_Persons,
Reser‌​vation.Room_Floor,
Re‌​servation.Room_Numbe‌​r,
Reservation.Room_T‌​ype,
Reservation.Vehi‌​cle_Number,
Customers‌​Details.Customer_Add‌​ress,
CustomersDetail‌​s.Customer_CNIC,
Cust‌​omersDetails.Custome‌​r_Full_Name,
Customer‌​sDetails.Customer_Ph‌​one_Number 
from 
Reservation
INNER JOIN CustomersDetails
    ON Reservations.Customer_ID = CustomerDetails.Customer_ID;

Upvotes: 3

Related Questions