Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I HAVE CODE FROM MULTIPLE TABLES AND WORK,
I NEED TO ADD ANOTEHER COLUMN FROM ANOTHER TABLE

CONECTION IS NAME ( name in code is "naziv"), quantity (name in code "kolicina")

What I have tried:

select x1.Naziv, x1.Nabavka, (ISNULL(x2.Prodaja,0)) as Prodaja, x1.Nabavka-(ISNULL(x2.Prodaja,0)) as 'Stanje' from (select naziv, sum(kolicina) as Nabavka from  
(select naziv as naziv, convert(float, kolicina) as kolicina from mp_ulazni_racun_roba_roba union all select naziv as naziv, convert(float, kolicina) as kolicina from mp_ulazni_racun_ostalo_roba ) a 
group by naziv) x1 left join(select roba, sum(kolicina) as Prodaja from 
(select roba, convert(float, kolicina) as kolicina from mp_racun_roba union all select roba, convert(float, kolicina) as kolicina from mp_faktura_roba ) b 
group by roba) x2 on x1.naziv = x2.roba 


ANOTHER TABLE COLUMN
select minimalna_dozvoljena_kolicina from dbo.roba_usluge
Posted
Updated 29-May-19 4:59am
Comments
[no name] 29-May-19 10:43am    
You should reformat you "query" because it looks like alphabet soup to everyone else.

Looks like decrypted source code.

1 solution

Gerry is right - that SQL is very hard to read.

But even formatted for readability, we probably can't help you as it stands: we have no idea what the relationship between the two tables is, and that's pretty much essential to actually fetching the data you want.

But in all likelihood, what you will need is a JOIN of some type (and it would probably improve the quality of your original query as well - but we have no idea of your data or what output you are trying to get so we can't be sure).
So it's time for some reading: SQL Joins[^]

Oh, and do everyone a favour: DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900