.net - making sql query to get first id of a tourist and then all of it's surcharges -
i've got these tables in database:
tourist - first table
tourist_id - primary key excursion_id - foreign key name...etc...
extra_charges
extra_charge_id - primmary key excursion_id - foreign key extra_charge_description
tourist_extra_charges
tourist_extra_charge_id extra_charge_id - foreign key tourist_id - foreign key
reservations reservation_id - primary key
..... tourist_reservations
tourist_reservation_id reservation_id - foreign key tourist_id - foreign key
so here example: i've got reservation reservaton_id - 27 reservation has 2 tourists tourist_id - 86 , tourist_id - 87 tourist id 86 has charges extra_charge_id - 7 , and extra_charge_id - 11; tourist id 87 has charge id - 10;
is possible make sql query , name , id of tourist , of charges
sothe output like:
tourist_id: 86, name:john, charges: 7,11
(here query made extra_charge_description of of tourists reservation_id = 27 )
select extra_charges.extra_charge_description,tourist_extra_charges.tourist_id extra_charges inner join tourist_extra_charges on extra_charges.extra_charge_id = tourist_extra_charges.extra_charge_id inner join tourist_reservation on tourist_extra_charges.tourist_id = tourist_reservation.tourist_id inner join reservations on reservations.reservation_id = tourist_reservation.reservation_idhe e reservations.reservation_id=27
the problem here have 3 records
so if tink there way in .net first name , charges of name - please advice because i'm new .net
if understood schema correctly, should you're looking for;
select t.tourist_id, t.name, stuff(( select cast(',' varchar(max)) + cast(tec.extra_charge_id varchar(max)) tourist_extra_charges tec tec.tourist_id = t.tourist_id order tec.extra_charge_id xml path('') ), 1, 1, '') charges tourist t;
Comments
Post a Comment