Activity Stream
48,167 MEMBERS
61103 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1.     
    #1
    Banned
    Website's:
    SKDown.Net WarezGuru.Org RARdownload.net

    Exclamation mysql query help ($5 reward) [SOLVED]

    i have the following tables

    client
    -----
    id
    name

    purchases
    ---------
    p_id
    c_id
    date
    ...

    i want to select all purchases for all clients where their last purchase was before date X.

    For example:
    Consider client 1, 2, 3 and 4.
    client 1 made 20 purchases before time X and just one recent purchase.
    Client 2 made 1000 purchases before time X
    Client 3 made only 1 purchase before time X
    Client 4 made only 1 purchase recently.

    The query should select "all" the purchases for client 2 and 4 only.

    first who writes the correct query gets the reward first.

    more info: http://www.besthostingforums.com/sho...2&postcount=10

    How the query works:
    we should select the MAX dat for each site and see if its maximum date entry is older than a year from now.
    if so we select all its rows. if not, we don't select any of its rows.

    solution: http://www.besthostingforums.com/sho...4&postcount=12
    tdsii Reviewed by tdsii on . mysql query help ($5 reward) i have the following tables client ----- id name purchases --------- p_id Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    th3fallen.com
    Edited after realized that c_id was client id lol


    $q=("SELECT client.id, client.name, purchases.p_id FROM client INNER JOIN purchases ON client.id=purchases.c_id ORDER BY purchases.date DESC");
    while ($r=mysql_fetch_assoc($q)) {
    echo $r['p_id'];
    }

    will loop though and show all pids sorted by day for preticular user

  4.     
    #3
    Member
    I would try a left join. I am not sure if it works because i am a little bit out of practice.

    But you could try this:



    SELECT p_id FROM purchases, LEFT JOIN client ON (client.id=purchases.c_id) WHERE id = 2 OR id=4;

    you should get the id of the purchases. you didn't mention the name of the purchases, you can add it after the SELECT and add a ,

    hope i could help

  5.     
    #4
    Member
    Website's:
    th3fallen.com
    oh wow i didnt realize the c_id was client id lmao time to rewrite.

  6.     
    #5
    Member
    Website's:
    th3fallen.com
    corrected mine sorry about that.

  7.     
    #6
    Respected Developer
    Website's:
    wrzc.org
    Why have both ye not included the Date part of the question?

    PHP Code: 
    $query $vbulletin->db->query_read(
        SELECT p_id
        FROM purchases, client
        WHERE id = cid
            AND (cid = 3 OR cid = 4)
            AND date > 123456789
        "
    ); 
    Question is confusing. If you don't want the time element leave out AND date > 123456789
    If you want it for all clients and not just 3 and 4 then leave out AND (cid = 3 OR cid = 4)
    Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic

    Huge list of Warez Sites and free Multiposter Templates

  8.     
    #7
    Banned
    Website's:
    SKDown.Net WarezGuru.Org RARdownload.net
    none are correct, please read again. i mentioned date X (int)

    I just want to remove all purchases for outdated clients. Thats all into the story.

    OFCOURSE i dont have 4 clients only (i have alot more). so please read the example for illustration

  9.     
    #8
    Member
    Website's:
    th3fallen.com
    i did include the date observe the ORDER BY purchases.date DESC i wasnt sure he if wanted the date sorted or to limit by the date

  10.     
    #9
    Respected Developer
    Website's:
    wrzc.org
    I don't follow the question still. So each client has a different date?

    EDIT oh now I think I follow. the 2 and 4 part are the answer not the question. That's what was confusing me.


    PHP Code: 
    $query $vbulletin->db->query_read(
        SELECT p_id
        FROM purchases, client
        WHERE id = cid
            AND date < 123456789
        "
    ); 
    is the answer so


    EDIT 2:
    First you say you want to select all purchases before a certain date. Later you say the result should be 2 and 4 but it should really be either 1 and 4 or else 2 and 3.
    Depending on what you want you just have to switch the < to >
    Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic

    Huge list of Warez Sites and free Multiposter Templates

  11.     
    #10
    Banned
    Website's:
    SKDown.Net WarezGuru.Org RARdownload.net
    ok, its always my mistake in elaborating..

    each purchase made have a date. so .. if the last purchase the client made was a year ago. i no longer want ALL his records in the database.

    if another client made very old purchase and a very recent purchase as well, i keep the old ones. so its not like remove all before date xxx

    i want to remove all purchase records for clients who's purchase is before xxx

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP - MySQL query to CSV export
    By ElitePirate in forum Web Development Area
    Replies: 2
    Last Post: 25th Jul 2012, 09:19 PM
  2. mysql query to export database
    By lenney in forum IP.Board
    Replies: 4
    Last Post: 7th May 2011, 03:43 PM
  3. MySql Query
    By GoPantheoN in forum Web Development Area
    Replies: 5
    Last Post: 8th Mar 2011, 02:09 PM
  4. WordPress database error MySQL server has gone away for query
    By blur88 in forum Webmaster Discussion
    Replies: 10
    Last Post: 27th May 2010, 08:43 PM
  5. Speed Up Your Web Site With MySQL Query Caching
    By BlaZe in forum Technical and Security Tutorials
    Replies: 1
    Last Post: 4th Nov 2009, 03:11 PM

Tags for this Thread

BE SOCIAL