Brain Dump - Database Issues

posted at 08:41:00
By Flipping Heck!
Posted In
Technical


[Warning.... Entering a slightly geeky zone]

A couple of few things have cropped up in the past two days that have caused a fair bit of hair pulling and have such simple solutions it's not true.

I'm sure at some point I will need to remember this information so I hope you don't mind that I put it here for future reference even if it is a bit off topic for this blog.

If you're not of a technical nature then feel free to fall asleep now... ;)

Problem 1 - Combining multiple SQL queries with sub-select statements (MYSQL).

I have a users table that I wish to join to a table containing the baskets that they have created and the languages of each item the user has selected.

I could have done this using multiple select statements or some kind of array and loop but this proved to be hugely processor intensive - something that we couldn't have as it the code's due to run on a shared server.

So, a colleague and I sat down and came up with a rather splendid query, much better than tonnes of evil joins .

Part of the problem also lay in the fact that we wanted a nice tabular layout for the results which wouldn't work with all of the queries I tried. It was fine for a single language but a right royal mess for table layouts.

Table Layout

Users Table
--------------------------
|User ID | User Name |
--------------------------
Basket Table
---------------------------------------------------------------
|User ID | Basket ID | Language ID | Catalogue Processed |
---------------------------------------------------------------

SQL Statement

SELECT UserTable.UserID, UserName, LanguageID, CatalogueID, Basketid,
(SELECT Count(LanguageID) FROM (BasketTable) where BasketTable.UserID = t.UserID AND
CatalogueProcessed=1 AND CatalogueID=1 and LanguageID = 1) AS English,
(SELECT Count(LanguageID) FROM (BasketTable) where BasketTable.UserID = t.UserID AND
CatalogueProcessed=1 AND CatalogueID=1 and LanguageID = 2) AS French,
(SELECT Count(LanguageID) FROM (BasketTable) where BasketTable.UserID = t.UserID AND
CatalogueProcessed=1 AND CatalogueID=1 and LanguageID = 3) AS German,
(SELECT Count(LanguageID) FROM (BasketTable) where BasketTable.UserID = t.UserID AND
CatalogueProcessed=1 AND CatalogueID=1 and LanguageID = 4) AS Italian
FROM (UserTable INNER JOIN BasketTable t on UserTable.CD_ID=t.UserID)WHERE
CatalogueProcessed=1 AND catalogueID=1 GROUP By UserID

Output

 --------------------------------------------------------------------
| UserID | UserName | BasketID | English | French | German | Italian |
--------------------------------------------------------------------
| 1 | Katy | 1234 | 4 | 0 | 2 | 0 |
--------------------------------------------------------------------
| 2 | Pierre | 1235 | 0 | 5 | 0 | 4 |
--------------------------------------------------------------------

Hooray!

Problem 2 - Memo fields being truncated to 255 characters (MS Access).

This one had me stumped for ages. Originally the script did truncate the field in question but it still did so when I removed the truncation - weird! Anyway, after much hair pulling it turned out to be the "SELECT DISTINCT" clause in the SQL statement. I'm not sure if this is a bug in the code or in Access itself and the way it handles DISTINCT but removing it from the SQL Statement returned the full contents of the memo field.

Weird!

Problem 3 - Scheduled Database Backups failing (MYSQL).

This was another annoying one. All user permission were set correctly and the backup ran when manually activated but wouldn't run as a scheduled task.

It turns out that the run command generated by MYSQL contains an error. Here's the command auto-generated by MYSQL:

"C:Program FilesMySQLMySQL Administrator 1.1MySQLAdministrator.exe" 
"-UDC:Documents and SettingsKaty WhittonApplication DataMySQL"
"-c" "-bpTest Backup" "-btC:" "-bxTest Backup"

You can see on the third line there's a command called "-c", changing this to "-C" or removing completely allows the backup to run as a scheduled task successfully.

Annoying!

[End slightly geeky zone]

Sorry for the off topic brain dump but if I didn't put it somewhere I'd forget what I'd done!



Tags:





Like this article? Add it to:

del.icio.us - Add URL  digg - Add URL  blinklist - Add URL  furl
- Add URL  reddit - Add URL  blogmarks - Add URL  magnolia - Add URL StumbleUpon Toolbar


 



Zen To DoneZen Habits HandbookBannerAdvertise on Flipping Heck
Visit the downloads area Contact Me Buy My EBook Hourly Rate Calculator Code Bank Advertise on this site Productivity Shop

Archive

Categories

 Blogging Business Coding Design Email From My Mobile Google GTD/Productivity Humour Life Hacks Motivation Movie Reviews News Personal Project Management Psychology/Body Language Quizzes/Tests Rants Review Site News Software Tips Technical

Recent Posts

 Threat of redundancy forcing us into unpaid overtime How to run an appraisal Stephen Covey launches a new Community Site Multitasking revisited: How much time are we wasting? How to run Productive Meetings - Guest post at Simpleology.com "Productive" Magazine Launched Shock Horror! Obama may lose Blackberry priviledges!

Recent Comments

 
Adrian says...

The link for BtB4 (Projects) and BtB5 (Review) is the same link. Just thought you should know.Thank....
 
web design says...

Hi, I have just visited your site and the info you have covered has been of great interest to me.....
 
web hosting says...

Great post, I admire the writing style :) A little off topic here but what theme are you using? Look....
 
Kevin says...

I found this post very informative. Here is another helpful body language tip. When you see their ey....
 
Chris says...

Randomly came across this post when searching for a solution to my own procrastination. I'd definit....
 
Pablo says...

Companies are not perfect; job policies in many cases are indeed absurd and unprofitable in the long....
 
Rojae Braga says...

Working beyond your usual working hours does not really mean increasing your productivity. In most t....
 
Quiz Master says...

A site that allows you to quickly create quizzes, tests and questions with full user tracking and le....
 
Ed says...

Hi there your readers may be interested in a new alternative to GTD called Dooster. It's a great on....
 
vijay says...

pig-headed weasel, they may ignore you completely and get you fired for going over their heads but i....

Stats

visitors
since February 2004
2102 Reading Now
Search
Click here for help on searching
 

View the Tag Cloud or View the Category Cloud

Subscribe

RSS Feed

Subscribe to the RSS Feed by clicking on the icon below and add the URL to your feed reader

Click here to Subscribe to the RSS Feed

Subscribe via Email

Email


Or subscribe via email



Delivered by FeedBurner


Twitter Updates

    follow me on Twitter

    Featured Posts

     GTD - Back to basics 6 - The round-up Managing Projects in one Place Managing Web Projects - The Whole Shebang Managing your time and procrastination levels with the ktDPlan ktGTD - Projects/Actions with a Moleskine Mindmapping Resources Manage Your Manager - How to cope with Ineffectual leadership Writing good meeting minutes revisited Getting Things Done with Thunderbird Get people re-involved: Change the format Project and Next Action Organisation Time Management: Procrastination vs GTD and Non-Conditional Scheduling Organising your desktop Recover "permanently" deleted items in Outlook Grocery Shopping Hack: Weekly Shopping Lists Using Flags and Rules In Outlook 2003 for GTD Make your blog search engine friendly My Life Organised and Outlook [argh!] How to market your blog and keep your readers GTD with a Pocket PC Improving Outlook with a custom dashboard Organising your Digital Photos Managing Tasks in Outlook Organising and Managing your DVD collection What is GTD?

    Popular Posts

     How to write good meeting minutes Writing good meeting minutes revisited Getting Things Done with Thunderbird Grocery Shopping Hack: Weekly Shopping Lists 7 Habits: Habit 4 - Think Win/Win Improving Outlook with a custom dashboard Writing Meeting Minutes - Meeting Mate v3 Organising your desktop GTD - Back to basics 6 - The round-up 7 Habits - Habit 5: Seek first to understand then to be understood

    Blog Roll

     A Bloke Near Where I live Cranky Middle Manager Show Dilbert Focused Performance GTD Wannabe My Boyfriend is a Twat Project Management Institute - eBusiness Specific Interest Group Random Acts Of Reality RoundACow Smidsy The Mad Admin The Register Wide Awake Wesley Wil Wheaton In Exile Suggest a site

    Admin

    To log in, enter your username
    and password below:

    This website and all its contents are © Katy Whitton 2012


    Powered By KWWD