获取名称而不是 ID
Get Names instead of IDs
我有一个 table product_sales
,其中包含其他 table 的外键,即 customer_id(customers
table)和measurement_id(共 measurements
table)。现在我想获取客户姓名和测量值而不是 ID。
product_sales
table:
id, customers_id, measurement_id
customers
table:
编号,customer_name
measurements
table:
编号,measurement_name
我试过了
SELECT product_sales.sale_id , customers.name, measurement_id product_sales.created_at, product_sales.total FROM
product_sales INNER JOIN customers on customers.id = product_sales.customers_id
product_sales 是一座桥梁 table,因此您可以将其他表加入其中
SELECT c.*,m.*
FROM customers c INNER JOIN product_sales ps ON c.id = p.customers_id
INNER JOIN measurements m ON p.measurement_id = m.id
我有一个 table product_sales
,其中包含其他 table 的外键,即 customer_id(customers
table)和measurement_id(共 measurements
table)。现在我想获取客户姓名和测量值而不是 ID。
product_sales
table:
id, customers_id, measurement_id
customers
table:
编号,customer_name
measurements
table:
编号,measurement_name
我试过了
SELECT product_sales.sale_id , customers.name, measurement_id product_sales.created_at, product_sales.total FROM
product_sales INNER JOIN customers on customers.id = product_sales.customers_id
product_sales 是一座桥梁 table,因此您可以将其他表加入其中
SELECT c.*,m.*
FROM customers c INNER JOIN product_sales ps ON c.id = p.customers_id
INNER JOIN measurements m ON p.measurement_id = m.id