last day (15 days later) » 

10:19 PM
0
A: inner join with two selects sql

Juan Carlos OropezaWITH cte as ( SELECT S.*, row_number() over (partition by S.SECURITY_ID ORDER BY SH.DATED DESC) FROM SECURITY S JOIN SECURITY_HIS SH ON S.SECURITY_ID = SH.SECURITY_ID AND S.INVESTMENT_OBJECTIVE = SH.INVESTMENT_OBJECTIVE ) SELECT * FROM cte WHERE r...

 
returned 0 match :(
 
Then the problem is with your data, can you prepare the sql fiddle sqlfiddle.com for me?
 
i exported the data but for some reason it is giving syntax error with that export
 
I know I try to load and didnt work, are you sure is SQL Server? in sql fiddle is a function Text to DDL you just copy the data with fieldname and he will create the table for you.
 
ok working on that!
i added table1 and table2. sqlfiddle.com/#!3/062b74
 
10:19 PM
I dont see fields DATED or INVESTMENT_OBJECTIVE
 
ok use this one with oracle sqlfiddle.com/#!4/699b4
 
Still not complete only one table and not data :(
 
i update the question with the right inserts for those tables.
is that fine? let me know
 
Isnt fine. And sorry for more I would like to help, I cant fix table for you.
 
you cant insert them? what is the issue? Thanks for your help!
 
10:19 PM
Give me an error, I try insert into my own sql server and didnt work. Missing , or missing '
You create the fiddle with oracle db?
 
you tried with the new inserts that i updated in the question? because i just tried it on sqlfiddle.com/#!4/c789f/2 and it worked.
yes i could use oracle
 
LOL, why you change it and didnt told me? Yes now is working sqlfiddle.com/#!4/699b4/6
 
lol i told you in the comments above "ok use this one with oracle sqlfiddle.com/#!4/699b4 ". All good we passed step one :)
 
Hi there
Try this http://sqlfiddle.com/#!4/699b4/13 You will see S.INVESTMENT_OBJECTIVE,
SH.INVESTMENT_OBJECTIVE are both null
 
ok will do
so there is two queries
the one starts with "With ..."
 
10:23 PM
Yes, the first one is testing to see why the second one doesnt work
the one with WITH has AND S.INVESTMENT_OBJECTIVE = SH.INVESTMENT_OBJECTIVE
and that doesnt bring any data because both investement are null
 
both nulls
is it possible to ignore nulls if both nulls
 
ok figured it out just adding something like or (origin.INVESTMENT_OBJECTIVE is NULL and history.INVESTMENT_OBJECTIVE is NULL)
should fix the issue
with my original query
like
 
AND ( S.INVESTMENT_OBJECTIVE = SH.INVESTMENT_OBJECTIVE
or (origin.INVESTMENT_OBJECTIVE is NULL and history.INVESTMENT_OBJECTIVE is NULL)
 
ok perfect :)
Thanks very much :)
 
10:32 PM
with that did you solve it?
 
yes a null checker would fix the returned results
select origin.* from
(select * from SECURITY) origin
inner join
(Select * from SECURITY_HIS t2 Where DATED = (SELECT MAX(DATED) FROM SECURITY_HIS t1 Where t1.SECURITY_ID = t2.SECURITY_ID)) history
on
origin.SECURITY_ID = history.SECURITY_ID
And (origin.INVESTMENT_OBJECTIVE = history.INVESTMENT_OBJECTIVE or (origin.INVESTMENT_OBJECTIVE is NULL and history.INVESTMENT_OBJECTIVE is NULL))
and origin.SECURITY_ID='IBMG7147S1008-NHK-FHKD';
 

last day (15 days later) »