php - 多表选择
问题描述
我不知道这是否可能,但这就是我想做的。我有三张桌子
账户
id | username | pass
汽车
id | plate | id_ac | kilometers // in the id_ac I add manual the id of the car's owner.
旅行
id | plate | places | date | active
现在我想在用户登录时查看他的车正在使用的行程。所以我想
SELECT from Trips the plate, places, date WHERE active=0 AND id= ? (the logged user's id)
但是 table trips 没有车主的 ID。所以我想以某种方式选择登录用户拥有的汽车的旅行表的值。
知道我该怎么做吗?
解决方案
你应该看看表连接。这看起来就像您正在寻找的内容:
SELECT t.plate, t.places, t.date FROM Trips as t JOIN Cars as c ON t.plate = c.plate WHERE t.active = 0 AND c.id_ac = ?
看看这个。这是解释表连接的一种很好的方式。 http://www.sql-join.com/sql-join-types
我没有进入数据库架构和更深层次的东西,但它可以帮助你完成手头的任务
推荐阅读
- python - 导入错误:无法从“pdfminer.utils”导入名称“open_filename”
- kubernetes - Kubernetes Configmap 目录和子目录文件
- azure - 对选定文件使用 AzureFileCopy 任务
- django-3 - 如何将变量传递给 django 3 帐户/登录页面?
- .htaccess - .htaccess 用通配符重写任何子域的子域
- shopify - 转换像素无法可靠触发
- kubernetes - 从集群内部调用外部 API
- java - 使用 readAllBytes 读取文件的字节,但是当我更改文件时输出没有改变
- python - Python:Gzip-package 无法将文件识别为 gzip-file
- rpgle - 调用 Qc3EncryptData 时出现 CPF9DEC 错误