table1:
id product price totalnumber
1 产品1 5.6 20
2 产品2 7.8 25
3 产品3 9.6 30
table2:
id product price
1 产品1 5.6
2 产品2 7.8
需求:查询table1,product和price与table2里的product和price一一对应的记录才会被查询出来。
结果是:
1 产品1 5.6 20
2 产品2 7.8 25
求教大神们如何写这个sql语句啊
SELECT
t1.*
FROM
tabel1 t1
JOIN tablel2 t2 ON t1.product = t2.product
AND t1.price = t2.price
select * from table1 a,table2 b where a.product=b.product and a.price=b.price
select a.id, a.product, a.price, a.totalnumber from table 1 a ,table2 b where a.product=b.product and a.price=b.price
```select * from table1 as t1 join table2 as t2 on t1.product = t2.product and t1.price = t2.price
select * from table1,table2 where table2.id=table1.id and table2.price=table1.price
select t1.* from table1 t1
RIGHT JOIN table2 t2 on t1.product=t2.product and t1.price=t2.price
水平有限,只能帮你到这了
SELECT table1.* FROM table1, table2 WHERE table1.product = table2.product AND table1.price = table2.price
首先你这个表不应该这么新建,太多重复的数据了。建议你用第三范式。SELECT t1.id t1.product t1.price t1.number FROM table1 AS t1 JOIN table2 AS t2 ON t1.produce=t2.product;