Jump to content

Joining subqueries


silkfire

Recommended Posts

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.