Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I count Uniques in mySQL ??

    Hi,

    A table which consists of lines with several entries for the same client
    and I want to count how many different clients there are.

    So I need to count only the number of uniques.

    This is what I have:

    PHP Code:
    $sql_cnt "SELECT item_id FROM main WHERE platform_no = '$platform_id' AND plat_type = '$Db_type'";

    $result_cnt mysql_query($sql_cnt)    or die("could not count the ITEMS"mysql_error() );  

    $num_cnt mysql_num_rows($result_cnt); 
    I NEED TO ADD SOMETHİNG LİKE :


    PHP Code:
    $sql_cnt "SELECT item_id FROM main WHERE platform_no = '$platform_id' AND plat_type = '$Db_type AND client_no IS UNIQUE'";

    $result_cnt mysql_query($sql_cnt)    or die("could not count the ITEMS"mysql_error() );  

    $num_cnt mysql_num_rows($result_cnt); 

    Does anyone know what the proper syntax is for this query ?

    thanks.


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Regular Coder
    Join Date
    Nov 2012
    Posts
    115
    Thanks
    7
    Thanked 12 Times in 12 Posts
    Something like this should do the trick I guess.

    PHP Code:
    $sql_cnt 
    "SELECT client_no
    FROM main
    WHERE platform_no = '$platform_id'
    AND plat_type '$Db_type'
    GROUP BY client_no"

    Last edited by Thyrosis; 01-08-2013 at 12:30 PM. Reason: changed select value

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thank you-

    I will give that a try
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    PHP Code:
    $sql_cnt "SELECT DISTINCT item_id FROM main WHERE platform_no = '$platform_id' AND plat_type = '$Db_type'";

    $result_cnt mysql_query($sql_cnt)    or die("could not count the ITEMS"mysql_error() );  

    $num_cnt mysql_num_rows($result_cnt); 
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #5
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hai Buddies....
    Already I have facing same problem select the unique name...so, this code also worked properly...
    $sql_cnt = "SELECT DISTINCT item_id FROM main WHERE platform_no = '$platform_id' AND plat_type = '$Db_type'";

    $result_cnt = mysql_query($sql_cnt) or die("could not count the ITEMS". mysql_error() );

    $num_cnt = mysql_num_rows($result_cnt);

  • #6
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hai Buddies...
    Already i have facing the same problem. select the unique thing from database
    I also worked the following query...
    $sql_cnt = "SELECT DISTINCT item_id FROM main WHERE platform_no = '$platform_id' AND plat_type = '$Db_type'"; \\Used DISTINCT

    $result_cnt = mysql_query($sql_cnt) or die("could not count the ITEMS". mysql_error() );

    $num_cnt = mysql_num_rows($result_cnt);

  • #7
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will help you to check it too.


  •  

    Posting Permissions

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