Professional Web Applications Themes

Mysql Database groupwise select - MySQL

Hi, I have a query problem that i hope somebody can help me solve. i have 2 tables user: id | name | ... 1 | mick | ... 2 | mat | ... account: id | mid | expiry | 1 | 1 | 20-05-2006 | 2 | 1 | 10-03-2004 | 3 | 1 | 06-07-2005 | 4 | 2 | 20-05-2005 | it may be considered a group-wise join but how can i get the resulting rows of all members to return: user.id | user.name | account.id | expiry 1 | mick | 3 | 06-07-2005 2 ...

  1. #1

    Default Mysql Database groupwise select

    Hi,

    I have a query problem that i hope somebody can help me solve.

    i have 2 tables

    user:
    id | name | ...
    1 | mick | ...
    2 | mat | ...

    account:
    id | mid | expiry |
    1 | 1 | 20-05-2006 |
    2 | 1 | 10-03-2004 |
    3 | 1 | 06-07-2005 |
    4 | 2 | 20-05-2005 |


    it may be considered a group-wise join but how can i get the resulting
    rows of all members to return:

    user.id | user.name | account.id | expiry
    1 | mick | 3 | 06-07-2005
    2 | mat | 4 | 20-05-2005
    and so on

    mick Guest

  2. #2

    Default Re: Mysql Database groupwise select


    mick wrote: 

    You wan't a match on user.id and account.mid with the highest value of
    account.id (even if the expiry date is not the most recent) right?

    If so you need a similar query to the one that I just posted in the
    Order By and Group By thread.

    Captain Guest

  3. #3

    Default Re: Mysql Database groupwise select


    mick wrote: 

    Since I'm in a good mood, here it is:

    SELECT `user`. * , `a1`. *
    FROM `user`
    LEFT JOIN `account` `a1` ON `user`.`id` = `a1`.`mid`
    LEFT JOIN `account` `a2` ON `a1`.`mid` = `a2`.`mid` AND `a1`.`id` <
    `a2`.`id`
    WHERE `a2`.`id` IS NULL

    Captain Guest

  4. #4

    Default Re: Mysql Database groupwise select


    mick wrote: 

    Since I'm in a good mood, here it is:

    SELECT `user`. * , `a1`. *
    FROM `user`
    LEFT JOIN `account` `a1` ON `user`.`id` = `a1`.`mid`
    LEFT JOIN `account` `a2` ON `a1`.`mid` = `a2`.`mid` AND `a1`.`id` <
    `a2`.`id`
    WHERE `a2`.`id` IS NULL

    Captain Guest

Similar Threads

  1. Contribute Failing to Launch Groupwise
    By invid23 in forum Macromedia Contribute General Discussion
    Replies: 2
    Last Post: December 5th, 01:54 PM
  2. MySQL Database not retrieving the full database
    By geetha.veeraiah@gmail.com in forum MySQL
    Replies: 4
    Last Post: July 21st, 09:34 PM
  3. MySQL subquery in select
    By Kasper K in forum MySQL
    Replies: 6
    Last Post: July 12th, 02:24 PM
  4. Groupwise Error with Contribute 3
    By JulzFSUSD in forum Macromedia Contribute General Discussion
    Replies: 6
    Last Post: August 17th, 06:37 AM
  5. Email PDF through Groupwise 6.0 - Form error help please?
    By Tim_Paris@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 7th, 11:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139