avatar
how to write this query# Database - 数据库
l*u
1
table 1
product no. description
001 aa
002 bb
003 cc
table 2
Product no transcaction
001 111
001 222
003 rrr
how can I write query to find the product in table 1 that doesn't have any
transaction in table 2. query should return 2 by using the above data.
avatar
R*r
2
SELECT t1.ProductNumber FROM
Table1 t1
LEFT JOIN Table2 t2 ON
t2.ProductNumber = t1.ProductNumber
WHERE t2.ProductNumber IS NULL

【在 l********u 的大作中提到】
: table 1
: product no. description
: 001 aa
: 002 bb
: 003 cc
: table 2
: Product no transcaction
: 001 111
: 001 222
: 003 rrr

avatar
l*u
3
we need to put this query into a tool. however the tool has
"select * from table t1 where" hardcoded, left join is before where, so how
can I left join with query start with select * from where
avatar
B*g
4
not exists

how

【在 l********u 的大作中提到】
: we need to put this query into a tool. however the tool has
: "select * from table t1 where" hardcoded, left join is before where, so how
: can I left join with query start with select * from where

avatar
l*u
5
we need to put this query into a tool. however the tool has
"select * from table t1 where" hardcoded, left join is before where, so how
can I left join with query start with select * from where
avatar
l*u
6
beijing code pls. thanks

【在 B*****g 的大作中提到】
: not exists
:
: how

avatar
B*g
7
NOT EXSITS (SELECT 1 FROM table2 t2 WHERE t2.no = t.no)
or
no NOT IN (SELECT no FROM table2 t2)

【在 l********u 的大作中提到】
: beijing code pls. thanks
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。