silkfire Posted May 18, 2011 Share Posted May 18, 2011 I've got a table with columns id, year and the 12 months. How do I join the result set if I want to select Nov, Dec where year is 2010 and Jan where year is 2011? Without selecting Jan 2010 and Nov, Dec 2011? Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/ Share on other sites More sharing options...
phppaper Posted May 18, 2011 Share Posted May 18, 2011 the 12 months are columns or rows? show us the structure. Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1216876 Share on other sites More sharing options...
silkfire Posted May 18, 2011 Author Share Posted May 18, 2011 Columns: id, year, Jan .... Dec Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1216886 Share on other sites More sharing options...
silkfire Posted May 18, 2011 Author Share Posted May 18, 2011 Can you help me out guys? I now need to compare a previous price with a current one and the problem is when I compare Dec with January of a next year. (I can't do this with PHP because I need the result of this query to make another query). Let's say I want to compare these two rows (even if it's not just these two rows, it should check in the whole table): ID, year, Jan ............(months)............., Dec 40432329, 2011, .............................................45.32 40432329, 2012, 28.45............................................. How do I select all IDs where Jan 2012 is LESS than Dec 2010? Remember that on most months it will compare to same row, for example Sep 2011 with Oct 2011. Tried with subquery but it said subquery returned multiple results. Help! Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1216996 Share on other sites More sharing options...
fenway Posted May 18, 2011 Share Posted May 18, 2011 You have a column called "Jan"? Seriosuly? Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1217158 Share on other sites More sharing options...
silkfire Posted May 18, 2011 Author Share Posted May 18, 2011 Why not? One price for each month. Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1217205 Share on other sites More sharing options...
fenway Posted May 20, 2011 Share Posted May 20, 2011 Why not? One price for each month. That requires one row per month, not one column per month. What if you even wanted to store 2 prices per month? Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1218152 Share on other sites More sharing options...
silkfire Posted May 21, 2011 Author Share Posted May 21, 2011 You, sir, shouldn't be on these forums, you can't help out anyway just giving people useless replies. I said I had one price in every cell, what is it you don't understand? Anyway I solved it myself. And if I would want more than one price in a cell I would separate them with a delimiter. Don't tell me how to build tables, fenway. Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1218398 Share on other sites More sharing options...
Pikachu2000 Posted May 21, 2011 Share Posted May 21, 2011 Just because his reply isn't the one you wanted to hear, doesn't make it useless. Especially since he's right. You're attempting to force a relational database to behave as a spreadsheet, which it is not. Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1218436 Share on other sites More sharing options...
fenway Posted May 22, 2011 Share Posted May 22, 2011 You, sir, shouldn't be on these forums, you can't help out anyway just giving people useless replies. I said I had one price in every cell, what is it you don't understand? Anyway I solved it myself. And if I would want more than one price in a cell I would separate them with a delimiter. Don't tell me how to build tables, fenway. Well, you don't know how to "build tables" -- so someone should tell you before you break something. I really hope you're not being paid for this work, since you're about to screw over your client. What you consider 'solved' everyone else in the world considers "broken". And don't tell me how to help -- I can't tell you how to listen. Quote Link to comment https://forums.phpfreaks.com/topic/236723-joining-subqueries/#findComment-1218666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.