Click here to Skip to main content
15,792,870 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
ADD TWO QUERY DIFFERENT TABLES TO ONE QUERY AND ONE TABLE


Need some good example

What I have tried:

ADD TWO QUERY DIFFERENT TABLES TO ONE QUERY AND ONE TABLE
Posted
Updated 5-Jul-23 5:27am

Based on your comment you can use Common Table Expressions - see WITH common_table_expression (Transact-SQL) - SQL Server | Microsoft Learn[^]

If you want clearer solutions then try rewording your question with sample data and expected results.
 
Share this answer
 
See here: SQL Joins[^] - they provide info and examples.
 
Share this answer
 
Comments
Stylus STYLUS 5-Jul-23 9:05am    
All need to be in one table

--query 1

select t.naziv, SUM(convert(float,t.kolicina)) as kolicina,t.CIJENA, SUM(convert(float,t.UKUPNO))as 'UKUPNO'
from
(select roba as naziv, Format(sum(kolicina),'#,0.00') as kolicina, Format((mp_cijena) ,'#,0.00') as 'CIJENA', Format(sum(iznos_sa_pdv) ,'#,0.00') as 'UKUPNO' from dbo.mp_racun_roba
where roba IN(select naziv from roba_usluge where podgrupa_artikala = 'Hrana') and id_fakture IN(SELECT id FROM dbo.mp_racun_lista WHERE datum = '2023-05-18')
group by roba, mp_cijena
union all
select roba as naziv,Format(sum(kolicina),'#,0.00') as kolicina,Format((mp_cijena) ,'#,0.00') as 'CIJENA', Format(sum(iznos_sa_pdv) ,'#,0.00') as 'UKUPNO' from dbo.mp_faktura_roba
where roba IN(select naziv from roba_usluge where podgrupa_artikala = 'Hrana') and id_fakture IN(SELECT id FROM dbo.mp_faktura_lista WHERE datum = '2023-05-18')
group by roba, mp_cijena
) t
group by t.naziv, t.CIJENA


--query 2

SELECT * FROM DBO.normativi_roba WHERE id_fakture IN (SELECT id FROM DBO.normativi_lista WHERE naziv='BUREK')

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