Web数据库子查询

发布于 2024-12-04 00:04:14 字数 932 浏览 2 评论 0原文

我正在努力使用 JavaScript 函数从 2 个不同的查询中获取数据。如果我在函数中单独执行查询,我只能从第二个查询中的第一个查询中获得最后的结果。我得出的结论是,我必须对这两个查询进行子查询,以便该函数能够正常运行。

以下是两个查询 (popt.products_options_id = prodOpId):

tx.executeSql('
SELECT DISTINCT
popt.products_options_id, 
popt.products_options_name 
FROM
products_options popt, 
products_attributes patrib 
WHERE
patrib.products_id="1" 
AND
patrib.options_id = popt.products_options_id 
AND
popt.language_id = "1"  
ORDER BY 
popt.products_options_name',
[], function (tx, results) {


tx.executeSql('
SELECT
pov.products_options_values_id,
pov.products_options_values_name, 
patrib.options_values_price, 
patrib.price_prefix 
FROM
products_attributes patrib, 
products_options_values pov 
WHERE
patrib.products_id = "1" 
AND
patrib.options_id ='+ prodOpId + ' 
AND
patrib.options_values_id = pov.products_options_values_id 
AND
pov.language_id = "1"', 
[], function (tx, results) {

I'm struggling with a JavaScript function to get data from 2 different queries. If I execute the queries separated in the function, I only get the last result from the first in the second query. I have come to the conclusion that I have to subquery the 2 queries so the function will run properly.

Here are both queries (popt.products_options_id = prodOpId):

tx.executeSql('
SELECT DISTINCT
popt.products_options_id, 
popt.products_options_name 
FROM
products_options popt, 
products_attributes patrib 
WHERE
patrib.products_id="1" 
AND
patrib.options_id = popt.products_options_id 
AND
popt.language_id = "1"  
ORDER BY 
popt.products_options_name',
[], function (tx, results) {


tx.executeSql('
SELECT
pov.products_options_values_id,
pov.products_options_values_name, 
patrib.options_values_price, 
patrib.price_prefix 
FROM
products_attributes patrib, 
products_options_values pov 
WHERE
patrib.products_id = "1" 
AND
patrib.options_id ='+ prodOpId + ' 
AND
patrib.options_values_id = pov.products_options_values_id 
AND
pov.language_id = "1"', 
[], function (tx, results) {

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-12-11 00:04:14

我解决了当前查询的问题:

tx.executeSql('
SELECT 
popt.products_options_id, 
popt.products_options_name,
pov.products_options_values_id, 
pov.products_options_values_name, 
patrib.options_values_price,
patrib.price_prefix 

FROM
products_options popt, 
products_attributes patrib, 
products_options_values pov 

WHERE 
patrib.products_id="1"

AND 
patrib.options_id = popt.products_options_id 

AND 
patrib.options_values_id = pov.products_options_values_id

AND 
popt.language_id = "1"

ORDER BY 
popt.products_options_name',

[], function (tx, results) {

i fixed my problem with the current query:

tx.executeSql('
SELECT 
popt.products_options_id, 
popt.products_options_name,
pov.products_options_values_id, 
pov.products_options_values_name, 
patrib.options_values_price,
patrib.price_prefix 

FROM
products_options popt, 
products_attributes patrib, 
products_options_values pov 

WHERE 
patrib.products_id="1"

AND 
patrib.options_id = popt.products_options_id 

AND 
patrib.options_values_id = pov.products_options_values_id

AND 
popt.language_id = "1"

ORDER BY 
popt.products_options_name',

[], function (tx, results) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文