Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 QUERY SQL ON TWO TABLE

Author  Topic 

pierre65
Starting Member

1 Post

Posted - 2015-04-26 : 09:16:59
I have two table
Table A
NUMORD
POSORD
ARTICOLO
AMOUNT
Table B
NUMORD
POSORD
ARTICOLO
DATACONSEGNA

HOW CAN I OBTAIN
ALL RECORDS OF TABLE A (THE TOTAL AMOUNT OF TABLE A IS ALWAYS ALL RECORDS OF TABLE A) AND ONLY IF THERE IS A RECORD WITH NUMORD POSORD ARTICOLO A FIELD IN THE QUERY WHERE THERE IS ALL FIELD OF TABLE A AND A FIELD (TABLE B) DATACONSEGNA AND THERE ISN'T BLANK ?

Kristen
Test

22859 Posts

Posted - 2015-04-26 : 12:38:02
This perhaps?

SELECT A.NUMORD, A.POSORD, A.ARTICOLO, A.AMOUNT, B.DATACONSEGNA
FROM Table_A AS A
LEFT OUTER JOIN Table_B AS B
ON B.NUMORD = A.NUMORD
AND B.POSORD = A.POSORD
AND B.ARTICOLO = A.ARTICOLO
AND B.DATACONSEGNA <> ''
Go to Top of Page
   

- Advertisement -