15,792,870 members
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

## Solution 2

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.

## Solution 1

See here: SQL Joins[^] - they provide info and examples.

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')