mysql - Left join with most recent records before a certain date -


i want select active record based on date. need create view 'select everything' subquery not going work.

but right can select 1 column because says

operand should contain 1 column(s)

i duplicate select fields want going performance extensive, plus have lot of columns on history table.

for simple example (link below), lets need phone number well.. idea how should go doing it? thanks.

sql fiddler: http://www.sqlfiddle.com/#!2/1ff7e/1

i think got it! seems work need more records try.

sql fiddler: http://www.sqlfiddle.com/#!2/1ff7e/3

still not working... zzz...i added few more test data turned out didn't work!

sql fiddler: http://www.sqlfiddle.com/#!2/360c1/1

my bad. it working! inserted 2 duplicate primary keys history. all!!!!

sql fiddler: http://www.sqlfiddle.com/#!2/274c5/1

you can add subquery select clause:

select user.username, user.password,        (select uh.name user_history uh uh.user_id = user.user_id , effective_date <= '2013-04-18' order effective_date desc limit 1),         (select uh.phone_number user_history uh uh.user_id = user.user_id , effective_date <= '2013-04-18' order effective_date desc limit 1)  user order username; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -