MySQL:translateid';价值观

MySQL:translateid';价值观,mysql,sql,database,Mysql,Sql,Database,我有一个表,其中包含许多列,这些列的ID(键)对应于其他表。 例如,我有一张出售汽车的表格 [table of cars that were sold] ( car_make_id , car_engine_id , car_model_id , car_radio_id , buyer_id , seller_id , car_tittle_id , sale_price ) 每个id字段都有另一个包含id和名称的表,如: [another table] ( car_make_id

我有一个表,其中包含许多列,这些列的ID(键)对应于其他表。 例如,我有一张出售汽车的表格

[table of cars that were sold]
(
  car_make_id
, car_engine_id
, car_model_id
, car_radio_id
, buyer_id
, seller_id
, car_tittle_id
, sale_price
)
每个id字段都有另一个包含id和名称的表,如:

[another table]
(
  car_make_id
, car_engine_id
, car_model_id
, car_radio_id
, buyer_id
, seller_id
, car_tittle_id
, sale_price
)

[and another table]
(
  car_make
, car_make_id
)

[and another table]
(
  car_title
, car_title_id
)
等等,…每个表名为
car\u lookup
car\u model\u lookup

不管怎样,只要不写一百万个子查询就可以加入所有这些。这个表中有数百万个条目,每增加一个连接都要花费大量的时间。我正在寻找一种快速有效的方法,将这些数据与另一个没有id但只有名称的表进行比较。假设我有一个兼容收音机的列表(品牌、型号、发动机、收音机),我想有一个列表,列出所有销售不兼容收音机的汽车的销售商的名字,以及他们进行了多少不兼容的销售

我一直在用perl做类似的事情,但运行起来可能需要几个小时。所以我正在寻找一些可以在mysql中完成的东西

附言:汽车只是一个例子,我实际上并没有使用汽车,但它说明了我的问题。我也无法更改数据库的设置方式,因为已经有大量代码查询数据

谢谢

您需要某种方法来告诉数据库每个ID要从哪些表中提取名称

如果这种查询速度太慢,也许可以优化数据库或MySQL服务器,使其能够更快地填充这些JOIN语句。尝试增加缓存大小(特别是当您的服务器有很多RAM时),并确保在这些查找表上有键索引

SELECT car_make, car_engine, car_model, car_radio,
       buyer, seller, car_title, sale_price FROM cars_sold
JOIN car_make_lookup USING (car_make_id)
JOIN car_engine_lookup USING (car_engine_id)
JOIN car_title_lookup USING (car_title_id)
JOIN car_model_lookup USING (car_model_id)
JOIN car_radio_lookup USING (car_radio_id)
JOIN buyer_lookup USING (buyer_id)
JOIN seller_lookup USING (seller_id)
JOIN car_title_lookup USING (car_title_id)

请发布一些示例数据和所需输出