Rows of table as field with where clause?

Discussion in 'MySQL' started by Supah Fly, Nov 22, 2009.

Thread Status:
Not open for further replies.
  1. #1
    i need no fields omitted (do i still use *?)

    table 1 layout:
    id | otherrow | numeric
    0 | anything | 1

    table 2 layout:
    id | month | year
    0 | 11 | 2009

    i want to have this query for the amount of rows:
    SELECT COUNT(*) FROM `table2` WHERE `id` = `idfromtable1` AND `month` = '11' AND `year` = '2009';
    Code (markup):
    table 1's query is like this:
    SELECT * FROM `table1` WHERE `otherrow` = 'anything' ORDER BY `numeric` DESC;
    Code (markup):
    i need to have the table 1 layout afterwards be:
    id | otherrow | numeric | tbl2count
    0 | anything | 1 | 1

    i've tried a lot things and nothing seemed to work.
     
    Supah Fly, Nov 22, 2009 IP
  2. Supah Fly

    Supah Fly Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    isn't it strange how after you ask for help you finally get the result you are looking for?

    accomplished with:
    SELECT *,(SELECT COUNT(*) FROM `table2` WHERE `id` = `table1`.`id` AND `month` = '11' AND `year` = '2009') AS tbl2count
    FROM `table1` ORDER BY `tbl2count` DESC, `numeric` DESC
    Code (markup):
     
    Supah Fly, Nov 22, 2009 IP
Thread Status:
Not open for further replies.