简体   繁体   中英

Compare column between two tables (greater and equal to)

I have two table, and i want to compare the two column from those two table. The column reflow in table f_product must greater and equal to column lreflow in table f_line. The coding that I used is

SELECT f_product.oiv,f_product.product,f_product.passive,f_product.pitch,f_product.reflow,f_line.lreflow,f_product.spi,f_product.scomp,f_product.pallet,f_product.printer,f_line.line  
FROM f_product,f_line  
WHERE f_product.passive=f_line.passive  
AND f_product.pitch=f_line.pitch  
AND f_product.spi=f_line.spi  
AND f_product.pallet=f_line.pallet  
AND f_product.printer=f_line.printer   
AND f_product.reflow >= f_line.lreflow  
AND oiv='PMLE4720A' .

However, the result display out did not compare out the column data in between f_product.reflow and f_line.lreflow. For example, the result still list out the result of reflow=8 and lreflow=10 where reflow is less than the value of lreflow. Is that my sql coding have any error?

I'm guessing this is Oracle? Sometimes it gets confused by the ambiguity between real where clauses and an implicit join using a where. I would recast it into ansi sql joins:

SELECT
.....
FROM
f_product a INNER JOIN f_line b ON 
(a.passive = b.passive AND
 a.pitch =b.pitch AND
 a.spi=b.spi AND
 a.pallet=b.pallet)
where oiv='PMLE4720A'
and  a.reflow >= b.lreflow  

Assuming the relationship between product and line is such that it makes sense to jion on these four fields...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM