i am having a problem in getting data from four tables based on a common field in one query.
1. i have product,open_ba lance,purchase, sales tables and product_id is primary key of product and foreign key in rest of the tables
2. i want to get the sum of the open_balance,pu rchase and sales for a product based on product key to get current quantity in stock
i used Left Join i think i am not writing the query correctly because it is doubling the value by repeating data based on conditions in query
This is the query -
select
-
p.p_manufacturer,
-
p.p_name,
-
sum(oqp.op_q_p_quant)as open_balance,
-
sum(pqp.pur_q_p_quant) as purchase_balance,
-
sum(sqp.sale_q_p_quant) as sales_balance
-
from product p
-
Left Join purchase_quant_price pqp
-
on p.p_id=pqp.pur_q_p_pro_id
-
Left Join open_quant_price oqp
-
on p.p_id=oqp.op_q_p_pro_id
-
left join sales_quant_price sqp
-
on p.p_id=sqp.sale_q_p_pro_id;
-
Please help me
Thanx in advance
3 2221 code green 1,726
Recognized Expert Top Contributor
GROUP BY the common field should solve it.
Or any unique field.
T-SQL for example would throw an error for this query because if one field is aggegated they all need to be.
This actually would have helped you in this situation.
hi code green,
thanks for your reply.
yes i too thought that but according to my knowledge of database i am not getting to the solution
before i use to do this with getting individual product_id by looping over product table and passing product_id to other tables and getting required data from that tables based on that product id
but i think this is very in-efficient solution and required too much looping and code and i think getting solution in this way is not a good practice.
so, please help me with this
code green 1,726
Recognized Expert Top Contributor
Try
GROUP BY p.p_id
This would only return unique p_id.
If that is what you are looking for
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: HB Kim |
last post by:
Hello,
What could possibly cause data in the SQL server database to be
removed, except being deleted manually? We had a couple of situations
where data in certain records disappeared although the records were
still there. The data is entered and editted through the web interface
in ASP. The web interface is accessed by anyone who has an account in
our database.
I am more of a web programmer, not a SQL server administrator, so not
very...
|
by: serge |
last post by:
My project is to automate testing of Stored Procedures
of type SELECT (at least for now).
I want to create a table where each stored procedure's
input parameter values are entered and in another table
the expected result value(s) are entered when executed
against a sample database containing manually entered
and verified data.
My current problem is that the stored procedures' input
|
by: Wilfried |
last post by:
Hi,
I have 5 tables:
main
data1
|
by: john woo |
last post by:
Hi
I'm not sure it's possible that using javascript to locate/get
components X|Y then other language, like java-jsp to save/retrive these
data.
For instance, a GUI presents a layout of tables/chairs for a
exhibition, some small images represent tables/chairs of various
sizes/styles, which considered as movable components in this GUI, and
their positions specified by X|Y.
|
by: hpaisawala |
last post by:
Hiya,
Is it possible to create a command button on a form and code it such
that it goes to a particular field and changes the data type property
of that filed from Auto Number to Number.
Many Thanks and Kind Regards,
Hussain
| |
by: NumberCruncher |
last post by:
Hi All,
I am struggling with setting up my first system of tables, forms,and reports, and could use your help!
I am setting up a database to keep track of the production of a produced item. The item is a panel, with a specific texture. There are standard panels that are then produced in a limited number of specific textures. The number of panels/project varies, so I keep track of the actual number of panels per project with the count:...
|
by: jpr |
last post by:
Hello,
My database has 5 tables.
WHen I add data to one table, it runs an append query that copies three
records to other 4 tables.
The main table is MASTER. The data I copy are: ID, SSN and PURGE DATE.
I would like to create a delete query that would delete all records in
all tables that show a date older that the one in the PURGE DATE. I use
|
by: nehashri |
last post by:
hi
i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children as fields. Also in policy table the firlds are:- ID, date_of_policy, no_policy, amount_paid, amount_balance and similarly the 3rd ie., staff has few fields. all three are linked my a common field which is ID
all i want is when the user searches...
|
by: Inbaraj |
last post by:
Hi..
In oracle i am having 100 tables each contains more then 500 records... Due to virus attack i lost the C drive (OS) in my PC but i installed oracle in D: drive. No i want to retrive the data can any one help me how to do this...
its urgent for me...
thanks in advance..........
with reg
Inba
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |