query query
- Started
- Last post
- 21 Responses
- emecks
it's been waaaay too long since I touched mySQL, hell my SQL didn't even have pubes last time I touched it so now I'm confused...
say I have a table with 4 columns:
ID (int) (unique)
name (varchar)
email (varchar)
unitsPerYear (int)I want to run a query which returns the lowest unique unitsPerYear, how please?
- moth0
SELECT * FROM mxTable
ORDER BY unitsPerYear DESC?
Or were you after something different?
- moth0
Sorry - typo:
SELECT * FROM mxTable
ORDER BY unitsPerYear ASCyou can add
LIMIT 1
to return the lowest..
- emecks0
cheers moth!!
but that won't tell me whether or not the value of unitsPerYear is unique or not will it??
- ephix0
or just use SELECT UNIQUE
- moth0
^^
- emecks0
cheers lads!
a spliff in your memory this evening :)
- flavorful0
SELECT TOP 1 unitsPerYear FROM emecksTable ORDER BY unitsPerYear DESC
- flavorful0
Throw in a "WITH (NOLOCK)" statement after your table name if you want to be nasty.
- moth0
I should be the resident guru on this now. Some of the queries I had to write for a recent project were about 60 lines long and contained more joins than I care to see again.
- flavorful0
Pfft ... 60 lines?
What is this amatuer hour?
haha, :D
I have one script going to Production today that clocks in at 1157.
- flavorful0
... Props to me for spelling, "amateur", wrong, hahah.
- emecks0
I should be the resident guru on this now.
moth
(Jun 21 07, 07:54)you are.
- flavorful0
* Challenges moth.
MSSQL ISH BETTAH!
- moth0
MS?
Toy...
- moth0
I have one script going to Production today that clocks in at 1157.
flavorful
(Jun 21 07, 08:03)Post it.
- flavorful0
What can I say, I love sub queries, haha!
And as far as posting it, why that would be giving away trade secrets and confidential information in regards to database structure and the inner workings on how the main system I work on in fact works.
And you know this man!*
* I have no idea why I typed that in a Chris Tucker voice.
- moth0
I didn't really expect you to post it.
You can perform sub queries in MySQL.
- moth0
And as for 1000+ lines - you're obviously doing something grossly inefficient!
- flavorful0
OR SO EFFICIENT IT WOULD BLOW YOUR MIND!!!!!
- Point50
* I have no idea why I typed that in a Chris Tucker voice.
flavorful
(Jun 21 07, 08:33)
--------
uh, maybe because it just isn't possible not to