Home » SQL & PL/SQL » SQL & PL/SQL » Joined two tables on one row
Joined two tables on one row [message #679775] Wed, 25 March 2020 11:21 Go to next message
Gin min
Messages: 5
Registered: March 2020
Junior Member
Hi.

I need help about the query.
For example. Two tables one stock_in and 2nd stock_out.

Stock_in

Date product name qty
1/03/20 ABC 100
3/03/20 ABC 200
6/03/20 ABC 100

stock_out

Date product name qty
4/03/20 ABC 50
5/03/20 ABC 100

Sir,
I nèed Result this.

Date product name qty
1/03/20 ABC 100
3/03/20 ABC 200
4/03/20 ABC 50
5/03/20 ABC 100
6/03/20 ABC 100

Please guid me
Re: Joined two tables on one row [message #679776 is a reply to message #679775] Wed, 25 March 2020 11:26 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Align the columns in result.
Also always post your Oracle version, with 4 decimals (query v$version), as often solution depends on it.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Have a look at FULL OUTER JOIN.
Now you have to answer the question: what should be the result in case there is the same date for the same product in both tables?

[Updated on: Wed, 25 March 2020 11:29]

Report message to a moderator

Re: Joined two tables on one row [message #679777 is a reply to message #679775] Wed, 25 March 2020 11:44 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3269
Registered: January 2010
Location: Connecticut, USA
Senior Member
UNION ALL + ORDER BY.

SY.
Re: Joined two tables on one row [message #679778 is a reply to message #679777] Wed, 25 March 2020 12:04 Go to previous messageGo to next message
Gin min
Messages: 5
Registered: March 2020
Junior Member
Thanks for reply .
Sir want to guide you that one column name (date) is same in two tables.

Date product name qty
1/03/20 ABC 100
3/03/20 ABC 200
4/03/20 ABC 50
5/03/20 ABC 100
6/03/20 ABC 100
I mean,I need result in date wise from two tables
Re: Joined two tables on one row [message #679779 is a reply to message #679778] Wed, 25 March 2020 12:25 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Michel Cadot wrote on Wed, 25 March 2020 17:26

Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Align the columns in result.
Also always post your Oracle version, with 4 decimals (query v$version), as often solution depends on it.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.
...
Re: Joined two tables on one row [message #679780 is a reply to message #679778] Wed, 25 March 2020 18:19 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3269
Registered: January 2010
Location: Connecticut, USA
Senior Member
Again, use UNION ALL + ORDER BY.

SY.
Re: Joined two tables on one row [message #679781 is a reply to message #679780] Thu, 26 March 2020 00:10 Go to previous messageGo to next message
Gin min
Messages: 5
Registered: March 2020
Junior Member
Thanks Sir
your help in this regard is highly appreciated
Re: Joined two tables on one row [message #679782 is a reply to message #679781] Thu, 26 March 2020 04:03 Go to previous messageGo to next message
cookiemonster
Messages: 13917
Registered: September 2008
Location: Rainy Manchester
Senior Member
Do you understand what UNION ALL does?
If not read the documentation
Do you understand what ORDER BY does?
If not read the documentation, and maybe do a SQL course

If you understand those two this is incredibly simple. So think about it and have a go instead of assuming this is too hard for you.
Re: Joined two tables on one row [message #679783 is a reply to message #679782] Thu, 26 March 2020 04:05 Go to previous messageGo to next message
Gin min
Messages: 5
Registered: March 2020
Junior Member
Thanks sir problem is solve
Re: Joined two tables on one row [message #679784 is a reply to message #679783] Thu, 26 March 2020 05:02 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

From OraFAQ Forum Guide, #12. If you found an answer yourself, post it. That way we know the issue is resolved and we might learn from it.

Repeatedly violating the forum rules is not a good way to get help in the future.

Previous Topic: Cursored FOR loops, PLS-00103 compile error
Next Topic: Alter Regex to validate email Domain on RFC 5322 from Java to Oracle sql
Goto Forum:
  


Current Time: Thu Mar 28 13:21:39 CDT 2024