Click here to Skip to main content
14,421,922 members
Rate this:
Please Sign up or sign in to vote.
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 5:59am
Comments
Gerry Schmitz 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100