Thread: SQL Query

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17
  1. #11
    Join Date
    Jun 2008
    Location
    Washington, DC
    Posts
    789
    Plugin Contributions
    7

    Default Re: SQL Query

    You will need a combination of the below sql to achieve what you want but this will get you started.
    Code:
    SELECT COUNT( DISTINCT `customers`.`customers_id` ) AS distinct_names, `customers`.`customers_firstname` , `customers`.`customers_lastname` , `customers`.`customers_email_address` , `customers`.`customers_telephone` , `address_book`.`entry_street_address` , `address_book`.`entry_suburb` , `address_book`.`entry_postcode` , `address_book`.`entry_city` , `address_book`.`entry_state`
    FROM `address_book` `address_book`
    INNER JOIN `customers` `customers` ON ( `customers`.`customers_id` = `address_book`.`customers_id` )
    GROUP BY `customers`.`customers_email_address`
    HAVING distinct_names = 1
    And if this is going to be daily app why not modify Export invoice totals to .csv file for Excel use for your use?
    • 446F63746F722057686F •

  2. #12
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: SQL Query

    without order table
    Code:
    SELECT address_book.entry_company, address_book.entry_firstname, address_book.entry_lastname, address_book.entry_suburb, address_book.entry_city, address_book.entry_state, address_book.entry_postcode, address_book.entry_country_id, countries.countries_name, customers.customers_telephone, customers.customers_email_address
    FROM countries INNER JOIN (address_book INNER JOIN customers ON (address_book.address_book_id = customers.customers_default_address_id) AND (address_book.customers_id = customers.customers_id)) ON countries.countries_id = address_book.entry_country_id;
    with order table
    Code:
    SELECT orders.customers_name, orders.customers_company, address_book.entry_firstname, address_book.entry_lastname, address_book.entry_street_address, address_book.entry_suburb, address_book.entry_city, address_book.entry_state, address_book.entry_postcode, address_book.entry_country_id, orders.customers_telephone, orders.customers_email_address
    FROM (address_book INNER JOIN orders ON address_book.customers_id = orders.customers_id) INNER JOIN customers ON (address_book.address_book_id = customers.customers_default_address_id) AND (address_book.customers_id = customers.customers_id);
    because I'm lazzy, all is done via ms-access && that works very well in phpMyAdmin

  3. #13
    Join Date
    Apr 2008
    Location
    UK
    Posts
    326
    Plugin Contributions
    1

    Default Re: SQL Query

    Hi Hugo

    Thanks very much for your answer it has eliminated the additional addresses from the one customer who entered them. There is one small problem, if a exsisting customer has come back another day to buy something else, then that entry also gets added to the results, so you will have the customer in one line and then again further down the list.

    Would it be too much to ask if you could solve that problem too?

    Thanks,

    Phil

  4. #14
    Join Date
    Apr 2008
    Location
    UK
    Posts
    326
    Plugin Contributions
    1

    Default Re: SQL Query

    Hi

    Actually don't worry about it, the accounts package takes care of duplicate entries.

    Thanks,

    Phil

  5. #15
    Join Date
    Jun 2005
    Posts
    120
    Plugin Contributions
    0

    Default Re: SQL Query

    a friendly recommendation: if you are going to be querying the database, it would be a good thing to learn mysql. it is pretty easy and you can teach it to yourself (i did). get a book and a gui interface. I use navicat (for mac). it allows you to run queries and tells you your mistakes... also has a helper to help build them (although i have never quite figured out how that works). phpmyadmin is fine if you know what you are doing but wont help you learn.

    I cant tell you how valuable it has been to know how to write these myself, or to be able to find what i need in the code and edit...

  6. #16
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: SQL Query

    "Minnie Mouse" - - Another NaviCat advocate!!!

  7. #17
    Join Date
    Jun 2005
    Posts
    120
    Plugin Contributions
    0

    Default Re: SQL Query

    THE BEST SOFTWARE EVER -- seriously, i learned mysql using it... !! i love it!!
    i have MAMP running on my mac. then i use navicat and CODA (also amazing). wow, what a combo is all i can say. (and inexpensive too!)

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 9
    Last Post: 12 Jul 2023, 12:26 AM
  2. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  3. v151 SQL query setup. How do I TEST a query 'off-line'?
    By lewisasding in forum General Questions
    Replies: 3
    Last Post: 8 Mar 2013, 12:24 AM
  4. Replies: 2
    Last Post: 15 Aug 2011, 04:58 AM
  5. Sql Query
    By bebijuteria in forum General Questions
    Replies: 9
    Last Post: 3 Nov 2007, 05:49 AM

Posting Permissions

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