1

So I'm joining two tables together and then I'm trying to order first by PID and then within PID order by Month. I can manage to get the query working and ordering by PID but when I try to order by month as well the query keeps running out of memory.

SELECT l.Name, l.PID, Z.Month
FROM Z
INNER JOIN l ON l.Name=Z.Name
ORDER BY l.PID, Z.Month ASC;

Desired output:

Bob, 1, 01
Bob, 1, 02
Bob, 1, 04
Gary, 2, 03
Gary, 2, 08
Louis, 3, 01
Louis, 3, 02

etc. Note how month is ordered inside of the PID order. Both Month and PID are integers.

Mitchell
  • 169
  • 1
  • 14
  • looks ok to me..Are you saying it works with just one order by element? – TGH Jul 09 '14 at 02:15
  • It looks good and it should work for both order by. Please provide the error you are getting – Ashish Rajput Jul 09 '14 at 02:21
  • Weird, it runs when I limit it by 100. But it still takes several minutes to do so! I wonder why it's taking SO long just to order it by month? – Mitchell Jul 09 '14 at 02:35
  • Which DBMS are you using ("*keeps running out of memory*" sounds weird) –  Jul 09 '14 at 06:00
  • Are the names unique in each table? Do the character sets and collations match? How large are the tables? – Jan Hettich Jul 09 '14 at 06:39
  • I'm using HeidiSQL. Yeah everything is fine - I got it working by limiting the query to only return a few million rows at a time. The tables are 2GB and 500MB. – Mitchell Jul 10 '14 at 01:17

0 Answers0