MySQL : JOIN on most "recent" date I have two tables : orders and clients. Clients have one or more Orders (JOIN condition : clients.id = orders.client_id). I need to retrieve every client with their most &quot;recent&quot; order, based on a date column (named created) in orders table, in one request if possible. Everything I tried retrieve each client with the first order found, not the last (and I can't rely on the primary key for that). How should my request look like? I could try a subquery with a MAX(created) but two problems:  There could be more than one order with the same date. I'd need to order them by ID but it's impossible inside a subquery? I need to retrieve more than just the date column.
How can I SELECT rows with MAX(Column value), PARTITION by another column in MYSQL? My table is:     id home datetime player resource     1 10 04/03/2009 john 399   2 11 04/03/2009 juliet 244   5 12 04/03/2009 borat 555   3 10 03/03/2009 john 300   4 11 03/03/2009 juliet 200   6 12 03/03/2009 borat 500   7 13 24/12/2008 borat 600   8 13 01/01/2009 borat 700     I need to select each distinct home holding the maximum value of datetime. Result would be:     id home datetime player resource     1 10 04/03/2009 john 399   2 11 04/03/2009 juliet 244   5 12 04/03/2009 borat 555   8 13 01/01/2009 borat 700     I have tried: -- 1 ..by the MySQL manual:   SELECT DISTINCT   home,   id,   datetime AS dt,   player,   resource FROM topten t1 WHERE datetime = (SELECT   MAX(t2.datetime) FROM topten t2 GROUP BY home) GROUP BY datetime ORDER BY datetime DESC  Doesn't work. Result-set has 130 rows although database holds 187. Result includes some duplicates of home. -- 2 ..join  SELECT   s1.id,   s1.home,   s1.datetime,   s1.player,   s1.resource FROM topten s1 JOIN (SELECT   id,   MAX(datetime) AS dt FROM topten GROUP BY id) AS s2   ON s1.id = s2.id ORDER BY datetime   Nope. Gives all the records. -- 3 ..something exotic:   With various results.
Prove that $\sin(2A)+\sin(2B)+\sin(2C)=4\sin(A)\sin(B)\sin(C)$ when $A,B,C$ are angles of a triangle Prove that $\sin(2A)+\sin(2B)+\sin(2C)=4\sin(A)\sin(B)\sin(C)$ when $A,B,C$ are angles of a triangle   This question came up in a miscellaneous problem set I have been working on to refresh my memory on several topics I did earlier this year. I have tried changing $4\sin(A)\sin(B)\sin(C)$ to  $$4\sin(B+C)\sin(A+C)\sin(A+B)$$ by making substitutions by reorganizing $A+B+C=\pi$. I then did the same thing to the other side to get $$-2(\sin(B+C)\cos(B+C)+\sin(A+C)\cos(A+C)+\sin(A+B)\cos(A+B))$$ and then tried using the compound angle formula to see if i got an equality. However the whole thing became one huge mess and I didn't seem to get any closer to the solution. I am pretty sure there is some simpler way of proving the equality, but I can't seem to figure it out. Maybe there is a geometric interpretation or maybe it can be done using just algebra and trig. Any hint's would be appreciated (I would prefer an algebraic approach, but it would be nice to see some geometric proofs as well) Best way to save a ordered List to the Database while keeping the ordering I was wondering if anyone has a good solution to a problem I've encountered numerous times during the last years.  I have a shopping cart and my customer explicitly requests that it's order is significant. So I need to persist the order to the DB.  The obvious way would be to simply insert some OrderField where I would assign the number 0 to N and sort it that way.  But doing so would make reordering harder and I somehow feel that this solution is kinda fragile and will come back at me some day.  (I use C# 3,5 with NHibernate and SQL Server 2005)  Thank you Variables are often adjusted (e.g. standardised) before making a model - when is this a good idea, and when is it a bad one? In what circumstances would you want to, or not want to scale or standardize a variable prior to model fitting?  And what are the advantages / disadvantages of scaling a variable? How to align content of a div to the bottom How could a gap between array modifier created objects be closed? I have 14.04.5/16.04 or newer and an AMD GPU. I'm not getting the performance I want, and some programs say they need things like OpenCL.  I've heard about fglrx, but if I try to install it on my machine, it breaks and I have no GUI.  Is there anything I can do to get my AMD card working to its full potential? Automatically login and lock I want to configure Windows 7 to login automatically after the computer is switched on. That's not because I'm lazy and don't like typing passwords. That's because I want programs that are configured to run on startup run automatically.  But I don't want everyone to see my desktop, so I want my computer to remain locked. When I'm ready to work, I just type my password and don't have to wait until all startup programs run. Why do some materials reflect (metals) and other materials reflect and refract (glass) from the quantum perspective? Recently I was asked to explain the difference between reflection and total internal reflection from a purely conceptual standpoint (no math).    Let me explain what I already know.  Reflection and refraction at the quantum level are the same thing.  Light is a photon.  A photon is a discrete particle that has wave characteristics (a finite wave traveling like a bullet).  As the photon travels it collides with electrons in the matter of the medium it is traveling in.  Depending on the energy of the photon and the allowed energy bands of the medium the photon cause the electron to jump up a level.  If the photon is absorbed then the medium will increase its motion (at the macro scale increasing its temperature).  If the photon is not absorbed it will be re-emitted (really as a new photon). I have read and watched Feynman's QED lectures and book and have a pretty good understanding of his process for determining how all these paths come together to give the net path of the photon.  The general rule of thumb is that the photon wants to take the path which requires the least amount of time.  I understand how this principle goes to explain refraction and reflection.    What I don't seem to understand is why does one material seem to cause a higher percentage of refraction compared to another (metal vs. glass).  What about the electron configuration of a the medium changes the net effect of the absorption and re-emissions of the photons?  Is there a change in the probability of the photon being re-emitted in a reverse direction?  Is there a farther distance the photon can travel before being incident onto an electron?  This is the part where my understand breaks down.    When you have hit the critical angle in a medium that refracts and the light completely reflects, are the photons moving is the same manner as they would be in a material that always reflects? How does this connect to the question in the previous paragraph?  I know I have a bunch of mini questions embedded in answering this one larger question.  Any help on any of the parts would be greatly appreciated? has a weird case of the mono, while .  Also, that question is missing some content at the end: In many scientific papers, the article before the word "Equation" is omitted. Is there any grammar statement behind this? For instance:     "Equation (8) contains various approximations, and we have to check their consistency." I have seen several answers and proofs here at MSE that a self-adjoint operator $T$ on a Hilbert space $H$ where $T^2=T$, implies $T$ being an orthogonal projection operator.   The thought struck me; what would happen if the condition $T^2=T$ is replaced by $T^3=T^2$ or instead by $T^4=T^3$ or why not more generally by $T^n=T^{n+1}$ for some $n\in\mathbb{N}$? Would this still imply $T$ to be an orthogonal projection operator?  I guess someone must have thought of this before me? In that case perhaps there is a reference in the literature for this or perhaps the proof is way simpler than I might expect? I am going to install Ubuntu to dual boot with Windows 8 soon, but one of my friends warned me that partitioning my hard drive will slow my computer down. I run on a 500GB HDD and 8GB of ram if that helps at all. Is that true if I do it? Enable USB debugging (under settings/applications/development) programmatically from within an app What's the incentive to flag duplicates? I only say duplicates but I think this could be extended to several other flagging reasons. Since accepted answers/upvotes don't get reverted on questions I see people sometimes cut and paste the answer from a duplicate question without flagging as duplicate. In the end they can usually score a few upvotes and even an accepted answer.  Found this related question:   Seems to have a lot of popularity but nothing ever happened  Jeff on Dupes     Those arguing for “remove reputation from dupes” have no idea of the   Frankenstein monster you’d be creating.      That would be an awesome rep-denial tool for griefing others, first of   all.      Second, it creates a MASSIVE disincentive to participation — even if   you had no idea there were duplicates, you could be bushwhacked at any   time even if you contributed a fantastic answer. Oops sorry dupe!   Zero rep, buddy! Bzzzzt! Go away! Take your awesome answer elsewhere!      Incentives are fine, but penalties are an incredibly bad idea and   would actively hurt users and the network.   I guess this answers my question, even if I disagree with jeff. I'm using Ubuntu 16.04 and there's no fglrx! What happened? I'm trying to make a list of ways to tell if a given degree sequence is impossible. For example $3,1,1$  is not possible because there are only 3 vertices in total so one can't have degree 3.  The list so far   vertices has degree equal to or larger than number of vertices sum of degrees is odd for n vertices if one has degree n-1 and another has degree 0 for n vertices the sum of the degrees cannot be greater than $n(n-1)$ because this would be have more edges than a complete graph If I want to use objects as the keys for a Dictionary, what methods will I need to override to make them compare in a specific way?  Say I have a a class which has properties:  class Foo {     public string Name { get; set; }     public int FooID { get; set; }      // elided }    And I want to create a:  Dictionary&lt;Foo, List&lt;Stuff&gt;&gt;   I want Foo objects with the same FooID to be considered the same group.  Which methods will I need to override in the Foo class?  To summarize: I want to categorize Stuff objects into lists, grouped by Foo objects. Stuff objects will have a FooID to link them to their category. Cutting a circular hole in a hollow cylinder without distorting the cylinder Whenever I try to cut out a circular hole in either a cylinder or sphere the polygons around the circular hole always have distorted normals after smoothing. Is there anyway to fix this. I've tried using the remesh modifier but wind up with some pretty ugly results. Limit $c^n n!/n^n$ as $n$ goes to infinity Let $c&gt;0$ be a real number. I would like to study the convergence of $a_n := c^n n!/n^n$, when $n \to \infty$, in function of $c$.   I know (from  question) that $n!&gt;(n/e)^n$, so that $c^n n!/n^n&gt;1$ for $c ≥e$. But this doesn't imply that the sequence goes to infinity. And I'm not sure what to do for $c&lt;e$. I tried usual tests (D'Alembert...), without any success. I would like to avoid using Stirling approximation.  Thank you for your help! Can you dispel a magic effect you can't perceive? Discussions about Dispel Magic seem to imply that as long as you can perceive a magic effect in range of the spell, you can try and dispel it.   See  and  from @Miniman:      knowing where it is means that you know where it is. This allows you to use spells like Dispel Magic to remove its invisibility.   But what if you can't perceive it?  Two scenarios come in mind:   In combat, an evil wizard casts Invisibility on himself, walks away from the fray and uses the hide action on his next turn. Since PCs know/assume/deduce he's invisible and certainly in range of the spell, can one use Dispel Magic to end the spell? PCs enter a 80'&times;80' room. Can one declare: "I dispel any Invisibility spell in range", thus revealing one (the closest?) invisible enemy in the room?   What's enough to enable a caster to cast Dispel Magic on a magic effect:    perceiving (seeing, hearing, smelling, etc.) it? knowing/assuming/deducing it's there? or merely suspect/predict it?