For examlpe, we have two tables:

cars:

[Postgres] Create VIEW for display join tables result

make:

[Postgres] Create VIEW for display join tables result

 

For cars table, we want to know 'make_name' instead of 'make_id', we can do with 'join' two tables. In order to make future query easy, we can create VIEW:

CREATE VIEW joined AS
SELECT cars.type, cars.cost, cars.model, make.name
  FROM cars
  INNER JOIN make ON (cars.make_id = make.id)
  ORDER BY cost DESC  LIMIT 30;

[Postgres] Create VIEW for display join tables result

 

Other example:

CREATE VIEW toyotas AS
SELECT cars.type, cars.cost, cars.model, make.name
  FROM cars
  INNER JOIN make ON (cars.make_id = make.id)
  WHERE make.name = 'toyota'
  ORDER BY cost DESC  LIMIT 30;

[Postgres] Create VIEW for display join tables result

相关文章:

  • 2021-07-29
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2021-08-01
  • 2021-09-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2021-08-12
  • 2022-01-16
相关资源
相似解决方案