Click here to Skip to main content
15,936,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The table structure is like this;

Table - 1

PROCESS_DATE  CLEARING_DATE  BATCH_NO         SLIP_NO  DOC_TYPE  CHEQUE_NO   UNIQUE_IDENTIFIER

2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     251088	     2020022571350010008500001
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     012057	     2020022571350010008500002
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     000093	     2020022571350010008500003
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     389389	     2020022571350010008500004
2020-02-22	  2020-02-25	 7135001-000850	  1        3	     679492	     2020022571350010008500005
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     389323	     2020022571350010008500006
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     012062	     2020022571350010008500007
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     679504	     2020022571350010008500008
2020-02-23	  2020-02-25	 7135001-000850	  2	       3	     389323	     2020022571350010008500006
2020-02-23	  2020-02-25	 7135001-000850	  2	       3	     012062	     2020022571350010008500007 



Table - 2

PROCESS_DATE  CLEARING_DATE  BATCH_NO         SLIP_NO  DOC_TYPE  CHEQUE_NO   UNIQUE_IDENTIFIER
2020-02-22	  NULL	         7135001-000850	  1	       2		 NULL        2020022271350010008500001
2020-02-22	  NULL	         7135001-000850	  2	       2		 NULL        2020022271350010008500002
2020-02-23	  NULL	         7135001-000850	  2	       2		 NULL        2020022371350010008500002
2020-02-25	  NULL	         7135001-000850	  1	       2		 NULL        2020022571350010008500001
2020-02-25	  NULL	         7135001-000850	  2	       2		 NULL        2020022571350010008500002



Out put i need
                 
PROCESS_DATE  CLEARING_DATE  BATCH_NO         SLIP_NO  DOC_TYPE  CHEQUE_NO   UNIQUE_IDENTIFIER

2020-02-22	  NULL	         7135001-000850	  1	       2		 NULL        2020022271350010008500001
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     251088	     2020022571350010008500001
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     012057	     2020022571350010008500002
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     000093	     2020022571350010008500003
2020-02-22	  2020-02-25	 7135001-000850	  1	       3	     389389	     2020022571350010008500004
2020-02-22	  2020-02-25	 7135001-000850	  1        3	     679492	     2020022571350010008500005
2020-02-22	  NULL	         7135001-000850	  2	       2		 NULL        2020022271350010008500002
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     389323	     2020022571350010008500006
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     012062	     2020022571350010008500007
2020-02-22	  2020-02-25	 7135001-000850	  2	       3	     679504	     2020022571350010008500008
2020-02-23	  NULL	         7135001-000850	  2	       2		 NULL        2020022371350010008500002
2020-02-23	  2020-02-25	 7135001-000850	  2	       3	     389323	     2020022571350010008500006
2020-02-23	  2020-02-25	 7135001-000850	  2	       3	     012062	     2020022571350010008500007  


What I have tried:

Is there any way to achieve this in SQL? it's urgent. Any help is really appreciated.

Thank You.
Posted
Updated 1-May-21 9:34am
v2

1 solution

UNION the 2 tables; then sort (ORDER) on SLIP_NO, PROCESS_DATE, DOC_TYPE.

How to order by with union in SQL? - Stack Overflow[^]
 
Share this answer
 
Comments
chamindat 2-May-21 3:55am    
It's not work for me. The base on my tables "process_date =2020-02-25" from table 2 not need to come to the final result

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