- 论坛徽章:
- 0
|
主表
tableOne 有字段
tableOne_id(pk), total_price,total_tax, dept_id,dept_name
明细表
tableTwo 有字段
tableTwo_id(pk),tableOne_id, project_name,material_name,material_id
pk表示 主键
请教如何 根据 project_name查询 tableOne的信息
如
select total_price,total_tax, dept_id,dept_name from tableOne,tableTwo t
where tableOne.tableOne_id = t.tableOne_id and t.project_name = '项目'
这条可以查询 主表 有相关明细的情况
如何能 当明细表数据没有的情况也能 查出来
比如 tableOne_id 的值 为 100, 但是 tableTwo中 却没有 tableOne_id为100的数据,这样的话 就查不出来数据了,
希望通过一条SQL语句来查询 以上两种情况 (1. 根据project_name查询主表信息 2. 当主表没有相关明细时根据主表ID能查询出记录)
谢谢, 菜鸟学习中 |
|