如何从两张桌子上看?

时间:2019-07-05 19:52:22

标签: sql sql-server sql-view

我有两个完全不同的表,如果它们的字段名不同,如何从它们中查看一个视图?

  • 我应该尝试在表数据中找到相等的值吗?
  • 我不想使用UNION ALL

这是我的餐桌范例:

select 
    person.name as Name
  , profession.specialty
  , pp.name as  FriendName
  , customer.purchase
  , appointment.date
from appointment

  inner join profession
   on appointment.profession_id = profession.id_person
  inner join person person
   on appointment.profession_id = person.id

  inner join customer
   on appointment.customer_id = customer.id_person
  inner join person pp
   on appointment.customer_id = pp.id


------------
select 
    dp.name as DoctorName
  , doctor.specialty
  , pp.name as PacientName
  , pacient.disease
  , appointment.date
from appointment

  inner join doctor
   on appointment.doctor_id = doctor.id_person
  inner join person dp
   on appointment.doctor_id = dp.id

  inner join pacient
   on appointment.pacient_id = pacient.id_person
  inner join person pp
   on appointment.pacient_id = pp.id

0 个答案:

没有答案