Syntax for db count query needed

Discussion in 'Ruby' started by Ruby Quest, Dec 28, 2006.

  1. Ruby Quest

    Ruby Quest Guest

    can any one tell me the controller syntax for db record count?

    I want to specify this mysql query syntax in controller

    select count(*) from tablename where user_id=7;

    what is the controller syntax similar to the above sql quert?


    thanks and regards
    Rubyquest

    --
    Posted via http://www.ruby-forum.com/.
     
    Ruby Quest, Dec 28, 2006
    #1
    1. Advertising

  2. Ruby Quest

    Guest

    On Thu, 28 Dec 2006, Ruby Quest wrote:

    > can any one tell me the controller syntax for db record count?
    >
    > I want to specify this mysql query syntax in controller
    >
    > select count(*) from tablename where user_id=7;
    >
    > what is the controller syntax similar to the above sql quert?


    Sure! I do it like this:

    count = ksdbh.count:)Tablename) {|r| r.user_id == 7}

    Other people probably do it differently, though. Details are important
    when asking a "How do I...?" question.

    I imagine that you are actually asking how to do that using ActiveRecord,
    right? If so, while you will probably get a correct answer for AR from
    someone on this list, the better place to ask those questions is the Rails
    list.


    Thanks,

    Kirk Haines
     
    , Dec 28, 2006
    #2
    1. Advertising

  3. Ruby Quest

    Ruby Quest Guest

    Ruby Quest, Dec 28, 2006
    #3
  4. Ruby Quest

    Guest

    On Fri, 29 Dec 2006, Ruby Quest wrote:

    > Thanks kirk Haines!
    >
    > It works...
    >
    > Thanks again


    That works for you? What ORM are you using? That was not AR syntax, but
    rather, syntax for the Kansas ORM.


    Kirk Haines
     
    , Dec 28, 2006
    #4
  5. Ruby Quest

    Ruby Quest Guest

    NO...i used below method and it works.

    @itemCount=Item.count:)all, :joins=>"my table joins goes here",
    :conditions =>["my conditions goes here"];


    sorry for the confusion....

    Thanks
    RQ


    > That works for you? What ORM are you using? That was not AR syntax,
    > but
    > rather, syntax for the Kansas ORM.
    >
    >
    > Kirk Haines



    --
    Posted via http://www.ruby-forum.com/.
     
    Ruby Quest, Dec 29, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giovanni Azua

    generic count report for JPQL query

    Giovanni Azua, May 31, 2009, in forum: Java
    Replies:
    0
    Views:
    2,059
    Giovanni Azua
    May 31, 2009
  2. efelnavarro09
    Replies:
    2
    Views:
    942
    efelnavarro09
    Jan 26, 2011
  3. Mark

    SQL Query using COUNT

    Mark, Jun 29, 2004, in forum: ASP General
    Replies:
    5
    Views:
    225
  4. AJ

    Count Query

    AJ, Jul 21, 2006, in forum: ASP General
    Replies:
    1
    Views:
    111
    Bob Barrows [MVP]
    Jul 21, 2006
  5. laredotornado

    Count results of a query?

    laredotornado, Feb 28, 2008, in forum: Ruby
    Replies:
    1
    Views:
    94
    Ilan Berci
    Feb 28, 2008
Loading...

Share This Page