TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
474
2.9k
201.2k
Select from multiple tables
Mar 23 2020 3:59 AM
Regard
select
x1.sifra
as
'Šifra'
, x1.naziv
as
Naziv, x2.naziv
as
Naziv, x2.sifra
as
'Šifra'
FROM
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
Prodaja
from
(
select
roba
as
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
kolicina
from
mp_racun_roba
group
by
roba, sifra )b
group
by
naziv, sifra, kolicina) x1
FULL
OUTER
JOIN
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
Nabavka
from
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
kolicina
from
dbo.mp_ulazni_racun_roba_roba
WHERE
id_fakture
IN
(
SELECT
id
FROM
dbo.mp_ulazni_racun_roba_lista
WHERE
magacin =
'Magacin robe maloprodaja'
)
group
by
naziv, sifra) a
group
by
naziv, sifra) x2
on
x1.sifra=x2.sifra
group
by
x1.naziv, x1.sifra, x2.sifra,x2.naziv
Result
I need two column, first and second...if change code...
select
x1.sifra
as
'Šifra'
, x1.naziv
as
Naziv
FROM
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
Prodaja
from
(
select
roba
as
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
kolicina
from
mp_racun_roba
group
by
roba, sifra )b
group
by
naziv, sifra, kolicina) x1
FULL
OUTER
JOIN
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
Nabavka
from
(
select
naziv, sifra,
sum
(
ISNULL
(kolicina, 0))
as
kolicina
from
dbo.mp_ulazni_racun_roba_roba
WHERE
id_fakture
IN
(
SELECT
id
FROM
dbo.mp_ulazni_racun_roba_lista
WHERE
magacin =
'Magacin robe maloprodaja'
)
group
by
naziv, sifra) a
group
by
naziv, sifra) x2
on
x1.sifra=x2.sifra
group
by
x1.naziv, x1.sifra
Need and first row to be code (Šifra) and name (Naziv)
Advice?
Where I wrong?
Thank you
Reply
Answers (
2
)
Select values frow both query MS SQL
Insert into from one to another table with different value