|
fletcher, unless I'm blind, that code should work. Perhaps you could provide code for creating the picture and comment tables with enough sample data to demonstrate the problem?
|
# ¿ Dec 28, 2007 22:50 |
|
|
# ¿ May 13, 2024 01:23 |
|
Xae, joins will possibly increase the number of fields returned, especially if one is performing a semi-join (joining table A against B, but only selecting columns from A). In fact, incorrectly using semi-joins causes people to "fix" the results by slapping in a DISTINCT, where the proper behavior would be to change from a join to an IN subquery.
|
# ¿ Jan 2, 2008 13:49 |
|
This uses SQL2005 Common Table Expressions, but you can easily just build the two tables manually.code:
code:
code:
|
# ¿ Jan 3, 2008 00:48 |
|
Shouldn't there be some documentation on MySQL full text search on how to do this stuff? I would be shocked if this were the first time such functionality has been required.
|
# ¿ Jan 7, 2008 18:50 |
|
Clever, but I don't believe that documentation actually addresses "how to do this stuff".
|
# ¿ Jan 7, 2008 20:27 |
|
If you give me sample data (more rows than would be displayed in your desired output) and the desired output, I'll give you a SQL statement that works. Or I'll be really amusing in my attempt.
|
# ¿ Jan 10, 2008 02:49 |
|
cletus42o, RDBMS?
|
# ¿ Jan 10, 2008 17:11 |
|
SQL2005, with a few of my own CLR functions that should be obvious or irrelevant:code:
code:
Victor fucked around with this message at 17:22 on Jan 10, 2008 |
# ¿ Jan 10, 2008 17:19 |
|
I was lazy and didn't generate create table statements and related annoyances. See http://luke.breuer.com/time/item/SQL_2005_tables_from_strings/201.aspx .
|
# ¿ Jan 10, 2008 17:25 |
|
code:
|
# ¿ Jan 10, 2008 22:35 |
|
The above can be simplified -- I'm too lazy and tired.
|
# ¿ Jan 10, 2008 22:48 |
|
Do you have an index on `DATE`? How about `status`?
|
# ¿ Jan 12, 2008 11:10 |
|
Is this a single index, or multiple? Indexes can be on multiple columns. In particular, you want an index on (status, DATE).
|
# ¿ Jan 12, 2008 14:26 |
|
We don't know the server's specs.
|
# ¿ Jan 12, 2008 16:54 |
|
Maybe the planets aren't aligned?
|
# ¿ Jan 12, 2008 20:58 |
|
Xae posted:Plus, if you can't be sure you data is accurate why are you bothering to store it?
|
# ¿ Jan 17, 2008 04:59 |
|
You're just assuming too much. The rule that programmer time is more valuable than computer cost is a good one, but it isn't all-covering, all-important, never-inapplicable. To give you an idea, checking a foreign key constraint can keep transactions open a tiny bit longer, which result in locks being held a bit longer, which can, if one is near a certain breaking point (think adding 1% to a fully packed highway), will cause the system to go crazy. Moreover, dealing with constraints can be a royal PITA, due to having to delete in the right order, and having major issues with self-referencing tables.
|
# ¿ Jan 17, 2008 05:35 |
|
Xae, one major problem with your argument is that you assume getting a new server is an easy thing to do. Combine legacy issues with politics, and it's not a simple choice. Yes, it would be nice if people were all-around competent and powerful hardware could simply be purchased. I know this because we recently got a $6K DB server and it screams. However, your making blatant generalizations are... unsettling.
|
# ¿ Jan 17, 2008 20:12 |
|
It's typically best to load the data you have into some table created to hold said data, and then do the transformation with SQL statements.
|
# ¿ Jan 18, 2008 21:12 |
|
code:
|
# ¿ Feb 1, 2008 06:51 |
|
I had "zzzzzz" written out, but then decided that was lame, breakable, and tried for something better. Oh well...
|
# ¿ Feb 1, 2008 21:46 |
|
Jethro posted:ORDER BY CASE WHEN manufacturer IS NULL THEN 1 ELSE 0 END, manufacturer
|
# ¿ Feb 4, 2008 07:09 |
|
kalleboo, where did you put the [code][/code] tags?
|
# ¿ Feb 5, 2008 20:09 |
|
Awww, I thought you were going to say that the forums were temporarily out code tags or something.
|
# ¿ Feb 6, 2008 00:37 |
|
It's blue! Prettttty...
|
# ¿ Feb 6, 2008 01:02 |
|
Walked posted:Can someone help me understand: Victor fucked around with this message at 19:40 on Feb 7, 2008 |
# ¿ Feb 7, 2008 19:12 |
|
Walked posted:Fixed problem number 1! code:
|
# ¿ Feb 8, 2008 22:41 |
|
If there's anything my explanation didn't cover, let me know and I'll fix it. I wrote it just for you!
|
# ¿ Feb 8, 2008 22:59 |
|
code:
|
# ¿ Feb 12, 2008 23:03 |
|
code:
|
# ¿ Feb 12, 2008 23:17 |
|
With SQL2005 row_number() syntax:code:
|
# ¿ Feb 12, 2008 23:39 |
|
SQL Server Management Studio? It's not awesome, but it has functional undo/redo, among other things.
|
# ¿ Feb 13, 2008 06:53 |
|
ray2k posted:the only gotcha that I think some of the script generations may not be 100% compatible with sql 2000. (Not sure on that, though.)
|
# ¿ Feb 13, 2008 19:07 |
|
Fart Shark, define "top selling stores". If you need only one record, I showed how to do this above when helping Stephen. What RDBMS are you using?
|
# ¿ Feb 14, 2008 17:44 |
|
code:
|
# ¿ Feb 15, 2008 16:31 |
|
code:
|
# ¿ Feb 19, 2008 16:49 |
|
GroceryBagHead posted:1. There are many grassy knolls code:
|
# ¿ Feb 19, 2008 16:50 |
|
I don't know how to say this, other than no. Anti-joins like that don't need DISTINCT.
|
# ¿ Feb 19, 2008 16:55 |
|
That's actually not surprising -- I have seen very few people add a condition to a left join statement that has nothing to do with the join. It's a sad state of affairs, that SQL is so poorly taught...
|
# ¿ Feb 19, 2008 18:39 |
|
|
# ¿ May 13, 2024 01:23 |
|
You're doing a GROUP BY and then selecting columns that aren't grouped by, without aggregating. That doesn't make sense. MySQL lets you do it because sometimes it works, and you're supposed to know when it won't, even though it might look like you're getting good data. Your code below is playing Implementation Roulette. This post gives a template for what you want to do: for every set of records, you want to choose the min/max by some criteria. You make that its own derived table, pull the min/max value(s) out, as well as whatever designs "set of records", and then join that back to the main table and get everything you need. Perhaps I should put this idea in tsunami...
|
# ¿ Feb 21, 2008 17:49 |