merge - Merging two MySQL tables with sorted datetime -
sorry if sounds silly. right now, have basic understanding of mysql , relational databases. can simple selects ;)
usual, did google , stackoverflow research before posting this, couldn't find suitable answer (the ones on every time "0" value).
try make generic possible useful else.
let's have 2 tables:
tbuy qtybuy : integer datebuy : datetime tsell qtysell : integer datesell : datetime
i able write query can have resulting table of qtybuy/qtysell sorted "merge" of 2 dates, e.g. if 2 tables "history" of items beign bought , sold, know history of item, sorted date.
know it's easy make 2 different selects , then, in whatever programming language using, merging result "by hand". wondering if there better way using mysql. thinking like
select * (select * tbuy union select * tsell) order whichdate?!
but not know how specify "whichdate". thank you.
have tried:
select "buy" action, qtybuy item, datebuy actiondate tbuy union select "sell" action, qtysell item, datesell actiondate tsell order actiondate
?
since can't guess qtybuy, don't know if instead should join tables.
as want date-line no wholes, need table dates. sql can read , combine values, not create them out of nothing.
Comments
Post a Comment