i used to think i understood SQL

    Date: 07/24/08 (MySQL Communtiy)    Keywords: database, sql

    I used to use MS Access a lot and I know a little about SQL. My company wants me to change job roles and part of my new role will be writing queries for our company database. All I've ever had to do with SQL was write simple queries, and I usually just built the query in Access and modified as needed. As a test for this position, which I don't really want, they had me write some test queries. This is the first one I came up with and it's so convoluted I ended up needing Access to do it anyway.


    SELECT
    tblCust.FName, tblCust.LName, tblAdvCust.CardID, tblContacts.Phone, tblAddresses.FirstLine, tblAddresses.SecondLine, tblAddresses.ThirdLine, tblAddresses.City, tblAddresses.State, tblAddresses.Zip, tblCountry.Description

    FROM
    tblCountry INNER JOIN (tblAddresses INNER JOIN (tblContactTypes INNER JOIN ((((tblCust INNER JOIN tblAdvCust ON tblCust.CustomerID = tblAdvCust.CustomerID) INNER JOIN tblCustomerMembers ON (tblCust.CustomerID = tblCustomerMembers.CustomerID) AND (tblCust.CustomerID = tblCustomerMembers.MemberID)) INNER JOIN tblDealer ON tblAdvCust.DealerID = tblDealer.DealerId) INNER JOIN tblContacts ON tblCust.OwnerID = tblContacts.ReferTo) ON (tblContactTypes.ContactTypeId = tblContacts.ContactTypeId) AND (tblContactTypes.ContactTypeId = tblContacts.ContactTypeId) AND (tblContactTypes.ContactTypeId = tblContacts.ContactTypeId) AND (tblContactTypes.ContactTypeId = tblContacts.ContactTypeId))ON tblAddresses.OwnerID = tblCust.OwnerID) ON tblCountry.CountryID = tblAddresses.CountryID

    WHERE
    tblDealer.DealerId="109" AND tblContactTypes.ContactTypeId=1;

    Now, maybe they haven't explained it to me well enough, maybe they think I have more experience with SQL than I do and just assume there are things I know that I don't. I don't know. But am I expected to be able to write this sort of thing by hand? If I won't have some tools at my disposal to write this up, how am I expected to do this? I can't even wrap my head around this and for the life of me, because of the way the relationships in the database are set up, I couldn't think of a simpler way to do it.

    I'm probably going to turn this job down but it seems like they really want me to do it. So if there's a simpler way to go about this, I want to be able to do it. But this is bollocks.

    Source: http://community.livejournal.com/mysql/130809.html

« Selective Replication in... || Memory leak? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home