Results 1 to 2 of 2

Thread: About a SELECT command to execute in my MysQL Database

  1. #1
    Carcinosi Guest

    Question About a SELECT command to execute in my MysQL Database

    Hello,

    I have a MySQL 5.0 Database used for management of my service, with 13 tables.

    The two tables most important now are "customers" and "cust_packages".

    The table "customers" has one column "cust_email". This column has e-mails of customers of the my service.

    The table named "cust_packages" has one column "cpack_canceldate". This column has the date of canceled accounts, for example '2008-04-03'. If the account is not canceled, so this column has '0000-00-00'.

    Both tables "customers" and "cust_packages" have "cust_custnr" and "cpack_usernr" respectively with interconnected values.

    These columns have an identification number exclusive for each customer.

    For example, I have one customer with the number '110002' in the column "cust_custnr" of the table "customers". The same number is in the column "cpack_usernr" of the table "cust_packages".

    I want to select all e-mails of customers with canceled accounts.

    But there is a problem. The same customer may have two accounts...the same number may appear two or more times in the colum "cpack_usernr" of the table "cust_packages". For example, the customer '110002' in the past cancelled his account, but recently he opened another account. Because this, the same number 110002 appear two times in the column "cpack_usernr" of the table "cust_packages". I need only exclusive customers with canceled accounts.

    So, I want to select all e-mails of customers with canceled accounts AND ONLY for customers which appear ONE TIME in the colum "cpack_usernr" of the table "cust_packages".

    Thanks.

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    Can you post the sql for the two tables? Not very clear what your saying. Try the code below but I would be amazed if it's what you want.

    Code:
    SELECT DISTINCT cust_email
    FROM customers, cust_packages
    WHERE cpack_canceldate <> '0000-00-00'
    AND customers.cust_custnr = cust_packages.cust_custnr
    ORDER BY cust_email ASC;
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Similar Threads

  1. Replies: 0
    Last Post: 01 Jul 2009, 05:57 AM
  2. Help with MySQL database design
    By justinmc in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 18 Mar 2008, 05:28 PM

Posting Permissions

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