gpt4 book ai didi

mysql - SQL从多对多+phonegap中选择

转载 作者:行者123 更新时间:2023-11-29 13:36:49 24 4
gpt4 key购买 nike

我有一个名为“lists”的表、一个“products”表和一个“lists_has_products”表。

我的表格列表:

  • id
  • name
  • imgsrc

我的表产品:

  • id
  • name
  • imgsrc
  • categoryid

我的表lists_has_products:

  • listid
  • productid

我想选择 listid 等于 ... 的所有产品。
我怎样才能做到这一点?我已经尝试过但没有结果:(我正在使用phonegap)

tx.executeSql("SELECT * FROM PRODUCTS p, LISTS_HAS_PRODUCTS l WHERE p.id = l.productid AND listid = " + listid, [], onSelectSupermarketsSuccess, onTxError);

他总是直接进入“onTxError”函数。这就是我填充lists_has_products 表的方式:

tx.executeSql('INSERT INTO LISTS_HAS_PRODUCTS (listid, productid) VALUES (1, 2)');    

最佳答案

您尝试过 JOIN 语法吗?

tx.executeSql("SELECT P.* FROM PRODUCTS P INNER JOIN LISTS_HAS_PRODUCTS L ON P.id = L.productid WHERE listid " + listid, [], onSelectSupermarketsSuccess, onTxError);

关于mysql - SQL从多对多+phonegap中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18632797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com