SQL从3个不同的表中获取值 [英] SQL Getting values from 3 different tables

查看:71
本文介绍了SQL从3个不同的表中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这开始让我头疼了。


我的发票表有Invoice_Id,Customer_Id和Product_Code


Invoice_Id是主键

Customer_Id是外键

Product_Code是外键


所以我正在制作数据报告而我可以通过连接发票和客户表中的检索数据来实现它,但是当我尝试从产品表中获取数据时,它会失败


这就是我的atm


InvoiceSQL =" SELECT * From Invoice INNER JOIN Customer ON Customer.Customer_Id = Invoice.Customer_Id WHERE Invoice.Invoice_ID =" &安培; Txt_InvoiceID.Text& " INNER JOIN产品ON Invoice.Product_Code = Product.Product_Code WHERE Invoice.Product_Code =" &安培; Txt_InvoiceProdCode.Text& "


任何人都可以提供帮助;)


btw即时通讯使用vb6和MS Access

Ok this is starting to hurt my head :)

I have a Invoice table that has Invoice_Id , Customer_Id and Product_Code

Invoice_Id is the primary key
Customer_Id is a foreign key
Product_Code is a foreign key

so im making a data report and i can get it to work with connecting an retrieving data from the invoice and customer table but when i try and get data from the product table it fails

this is what i have atm

InvoiceSQL = "SELECT * From Invoice INNER JOIN Customer ON Customer.Customer_Id = Invoice.Customer_Id WHERE Invoice.Invoice_ID=" & Txt_InvoiceID.Text & " INNER JOIN Product ON Invoice.Product_Code = Product.Product_Code WHERE Invoice.Product_Code =" & Txt_InvoiceProdCode.Text & ""

can anyone help ;)

btw im using vb6 and MS Access

推荐答案

我回头看,我不认为我需要


WHERE Invoice.Product_Code =" &安培; Txt_InvoiceProdCode.Text& "

最后
I was looking back and i dontthink i need the

WHERE Invoice.Product_Code =" & Txt_InvoiceProdCode.Text & ""

at the end


仍然需要帮助:)不能再进一步排序这个^^


抱歉不耐烦
Still need help though :) cant go any further without sorting this ^^

sorry for being impatient



仍然需要帮助:)不能再进一步排序这个^^


抱歉不耐烦
Still need help though :) cant go any further without sorting this ^^

sorry for being impatient



对不起,你太不耐烦了 - 我要禁止你一辈子...:D


说真的,我打算将这个帖子移到Access论坛,因为你会在那里找到更多的SQL专业知识。


我相信如果您可以复制并粘贴传递给SQL解释的字符串的实际内容(换句话说,由您向我们展示的代码构建的srting),这将有所帮助。


而且,你能否更详细地解释一下失败是什么?意味着在这种情况下?据我们所知,它可能检索到错误的数据,没有检索,返回错误,炸毁PC ......

Sorry, you''re too impatient - I''m going to ban you for life... :D

Seriously, I''m going to move this thread to the Access forum, as you''ll find much more SQL expertise there.

I believe it would help if you could copy and paste here the actual contents of the string passed to the SQL interpret (in other words, the srting built by the code you showed us).

And also, could you give a more detailed explanation of what "fail" means in this context? For all we know it might have retrieved the wrong data, retrieved nothing, returned an error, blown up the PC...


这篇关于SQL从3个不同的表中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆