You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MySQL从不同表中查询列表项(含表结构示例)

Querying Items from MySQL Tables: Inventory & SalesTaxes

Got it, let's walk through how to query data from your two tables. First, let's restate your table structures clearly for reference:

Inventory Table

INV_IdINV_NameINV_Rate
30Breakfast15.00
31Bike21.00
32Visit19.00

SalesTaxes Table

STX_IdSTX_TaxeNameSTX_Amount
8Tax 15.000
9Tax 25.000
10Tax 319.975

Now let's cover common query scenarios you might need:

1. Fetch all inventory items

If you just need to pull every entry from the Inventory table with all its details, use this straightforward SELECT statement:

SELECT INV_Id, INV_Name, INV_Rate
FROM Inventory;

This will return all rows exactly as they appear in your Inventory table structure.

2. Fetch all sales tax entries

Similarly, to get every tax record from the SalesTaxes table:

SELECT STX_Id, STX_TaxeName, STX_Amount
FROM SalesTaxes;

3. Combine data from both tables (assuming a relationship)

If your inventory items link to specific taxes (even though you didn't include a foreign key in the given structure), let's say there's an INV_STX_Id column in Inventory that maps to STX_Id in SalesTaxes. You can join the tables to get combined data like this:

SELECT 
    i.INV_Id,
    i.INV_Name,
    i.INV_Rate,
    s.STX_TaxeName,
    s.STX_Amount
FROM Inventory i
JOIN SalesTaxes s ON i.INV_STX_Id = s.STX_Id;

If you want to include inventory items that don't have an associated tax (and show NULL for tax fields), swap JOIN with LEFT JOIN.

4. Filter specific items

For example, to get only inventory items with a rate higher than 18:

SELECT INV_Name, INV_Rate
FROM Inventory
WHERE INV_Rate > 18.00;

Or to get taxes with an amount greater than 5:

SELECT STX_TaxeName, STX_Amount
FROM SalesTaxes
WHERE STX_Amount > 5.000;

If you had a specific combined query in mind—like calculating total cost including tax for inventory items—just let me know and I can tweak this further!

内容的提问来源于stack exchange,提问作者user9516731

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:37:06