Need help with MySql query syntax!

Discussion in 'MySQL' started by poopie, Jul 2, 2008.

  1. #1
    Hello everyone,
    I need some help writing this query.


    I got a DB with 9 user tables (one for usernames starting with a,b,c, another for d,e,f, and so on). The fields are -basically- Username and Update Date.

    I also have a tenth table which stores the usernames of a given user's FRIENDS.



    Now, I have to run a query to display a given user's (call him user A) FRIENDS, ordered by "update date" of those friends .... meaning I have to check which users were added as friends by user A, and then get their respective "update date" from one of the 9 tables according to their name.

    (if user A has two friends: one starting with letter 'a' and another with 'd', i'd have to check both abc and def tables to see which one of them has the most recent update date...)


    Any way ... I can't pull this join together :(
    Please help ! thanks in advance
     
    poopie, Jul 2, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thats probably the worst db design i've heard of for a long time :) I'd recommend redesigning the database, cause now it's not bad - it's very bad. How many users do you expect to have and how did you come with the idea of making 10 tables where 2 are sufficient ?
     
    xlcho, Jul 2, 2008 IP
  3. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I agree with xlcho. 10 tables?! Are you out of your mind? :S I mean, you need just 2 tables for that: user and friends.

    Redesign your databases, man.
     
    Ikki, Jul 2, 2008 IP
  4. gigapros

    gigapros Active Member

    Messages:
    71
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    65
    #4
    Why are you using multiple tables? Unless you have a HUGE number of records (in millions), I don't see a reason to partition your tables.
     
    gigapros, Jul 5, 2008 IP
  5. zerofill

    zerofill Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #5
    ok hehe I have to agree here what the heck do you have 9 user tables for? Trying to make yourself go nuts or something? You could use multiple joins but damn would that be insane if that database ever got to any size at all...Your queries would become so complex it would be unmanageable... Redeisgn it before you get to far into it. Thats just insane there...
     
    zerofill, Jul 7, 2008 IP