Jump to content

bubblegum.anarchy

Members
  • Posts

    526
  • Joined

  • Last visited

    Never

Posts posted by bubblegum.anarchy

  1. Also consider wrapping the strings with html content in single quotes so that the following:

     

    $departments .= "<select name=\"user_department\" size=\"5\" id=\"user_department\">$lst_departments</option>";
    

     

    Would be more readable in this format:

     

    $departments .= '<select name="user_department" size="5" id="user_department">$lst_departments</option>';
    

  2. yeah... event_rsvp would certainly make a good double for an invitation record with date set to null as default making the NOT rsvp'd query a great deal simpler:

     

    event_rsvp.id

    event_rsvp.event_id

    event_rsvp.member_id <= forgot this member earlier

    event_rsvp.date

     

    SELECT  member.id
         , member.name
         , event.name
    FROM event_rsvp
         INNER JOIN event ON event_rsvp.event_id = event.id
         INNER JOIN member ON event_rsvp.member_id = member.id
    WHERE event_rsvp.event_id = $event_id AND event_rsvp.date IS NULL
    

     

    much better!

  3. The three core tables:

     

    member.id

    member.name

     

    event.id

    event.name

     

    group.id

    group.name

     

    A table to track events rsvp:

     

    event_rsvp.id

    event_rsvp.event_id

    event_rsvp.date

     

    A table to track members in groups:

     

    member_in_group.member_id

    member_in_group.group_id

     

    To get a list of all members and their associated groups:

     

    SELECT member.id
        , member.name
        , group_concat(group.name SEPARATOR '\n') AS groups
    FROM member
        LEFT JOIN member_in_group ON member.id = member_in_group.member_id
        LEFT JOIN group ON member_in_group.group_id = group.id
    GROUP BY member.id
    ORDER BY member.name
    

     

    To get a list of all members that have rsvp'd an event:

     

    SELECT member.id
        , member.name
        , event.name
        , event_rsvp.date
    FROM event
         INNER JOIN event_rsvp ON event.id = event_rsvp.event_id
         INNER JOIN member ON event_rsvp.member_id = member.id
    WHERE event.id = $event_id;
    

  4. I get conflicting results.

     

    The following table definitions and record inserts:

     

    DROP TABLE IF EXISTS property;
    CREATE TABLE property (
         idINT NOT NULL AUTO_INCREMENT primary key,
         address CHAR(50)
    );
    
    INSERT INTO property (address) VALUES ('123 Fake Street, Faketown');
    
    DROP TABLE IF EXISTS deals;
    CREATE TABLE deals (
         property_id INT,
         deal_type_id INT,      
         sales_pitch TEXT,   
         price INT,
         INDEX (sales_pitch(10), price),
         PRIMARY KEY (property_id, deal_type_id)
    );
    
    INSERT INTO deals (property_id, deal_type_id, sales_pitch, price) VALUES
         (1, 1, 'buy buy buy', 100000),
         (1, 2, 'hurry hurry hurry', 100000),
         (1, 3, 'make an offer', 100000),
         (1, 4, 'hurry last days', 100000),
         (1, 5, 'once in a lifetime', 100000),
         (1, 6, 'golf course nearby', 100000),
         (1, 7, 'beach side property', 100000);
    

     

    The following explain:

     

    EXPLAIN 
    SELECT deals.property_id
    , deals.price
    #	, deals.sales_pitch
    #	, property.address
    FROM deals 
    LEFT JOIN property ON deals.property_id = property.id
    

     

    results:

    id  select_type  table     type    possible_keys  key      key_len  ref                     rows  Extra
    1   SIMPLE       deals     ALL     NULL           NULL     NULL     NULL                    7
    1   SIMPLE       property  eq_ref  PRIMARY        PRIMARY  4        test.deals.property_id  1     Using index   
    

     

    With only the index property_id in the SELECT values resulted in the type `index`:

     

    EXPLAIN
    SELECT deals.property_id
    #    , deals.price
    #    , deals.sales_pitch
    #    , property.address
    FROM deals 
         LEFT JOIN property ON deals.property_id = property.id;
    

     

     

    resulted in:

     

    id  select_type  table     type    possible_keys  key      key_len  ref                     rows  Extra
    1   SIMPLE       deals     index   NULL           PRIMARY  8        NULL                    7     Using index
    1   SIMPLE       property  eq_ref  PRIMARY        PRIMARY  4        test.deals.property_id  1     Using index 
    

  5. First, a question: Do you understand the following sentence?

     

    I cant figure out how to go about this as I don't be able to put in ore than one WHERE statement?
    

     

    And now the answer:

     

    SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
    FROM users, images
    WHERE users.id = images.id AND users.bandid = $bandid
    
    or
    
    SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
    FROM users
         INNER JOIN images ON users.id = images.id
    WHERE users.bandid =  $bandid
    

  6. Aliases will be required to distinguish identical column names, something like this:

     

    SELECT person.pid
        , person.name_first
        , baclabor.encounter_nr AS baclabor_encounter_nr
        , patho.encounter_nr AS patho_encounter_nr
        , chemlab.encounter_nr AS chemlab_encounter_nr
        , .... etc
    FROM care_encounter AS encounter...
    

     

    And then in PHP:

     

    <?php
    echo $rows['chemlab_encounter_nr'];
    ?>
    

     

    Consider trimming the selected values to only those that are required.

  7. The following query:

     

    SELECT person.pid
         , person.name_first
         , baclabor.*
         , patho.*
         , chemlab.*
    FROM care_encounter AS encounter
         INNER JOIN care_person AS person ON encounter.pid = person.pid
         LEFT JOIN care_test_findings_baclabor AS baclabor ON encounter.encounter_nr = baclabor.encounter_nr
         LEFT JOIN care_test_findings_patho AS patho ON encounter.encounter_nr = patho.encounter_nr
         LEFT JOIN care_test_findings_chemlab AS chemlab ON encounter.encounter_nr = chemlab.encounter_nr
    WHERE baclabor.encounter_nr IS NOT NULL 
         OR patho.encounter_nr IS NOT NULL 
         OR chemlab.encounter_nr IS NOT NULL
    

     

    Produces the following result:

     

    pid         name_first                                                   batch_nr    encounter_n room_nr     dept_nr     notes                                                                                                                                                                                                                                                           findings_in findings_cu findings_fi type                           entry_nr    rec_date    doctor_id                           findings_da findings_ti status      modify_id                           modify_time         create_id                           create_time         batch_nr    encounter_n room_nr     dept_nr     type                                     doctor_id                           findings_da findings_ti status      modify_id                           modify_time         create_id                           create_time         batch_nr    encounter_n job_id                    test_date   test_time   group_id                       type                                     validator       validate_dt         status               modify_id                           modify_time         create_id                           create_time         
    10000000    pig                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1           1           10000001                  2007-03-13  10:26:50    priority                       Chemical Test                                            0000-00-00 00:00:00                      admin                               2007-05-05 10:44:52 admin                               2007-03-13 10:26:50 
    10000000    pig                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      3           9           10000002                  2007-04-04  09:57:49    priority                       Chemical Test                                            0000-00-00 00:00:00 hidden                                                   2007-05-05 11:02:22 admin                               2007-04-04 09:57:49 
    10000000    pig                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      5           9           10000002                  2007-04-04  14:38:21    priority                       Chemical Test                                            0000-00-00 00:00:00                      admin                               2007-04-13 14:38:24 admin                               2007-04-13 14:38:21 
    10000000    pig                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      6           12          10000001                  2007-05-06  00:00:00    priority                       Chemical Test                                            0000-00-00 00:00:00                                                          2007-05-03 14:35:59                                     0000-00-00 00:00:00 
    10000005    kib                                                          4           13                      0                                                                                                                                                                                                                                                                           0           0           0           Bacteriological Test                       0000-00-00                                      0000-00-00  00:00:00                                                    2007-05-05 11:00:01                                     0000-00-00 00:00:00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    10000006    test                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     4           14          10000003                  2007-04-11  16:59:25    priority                       Chemical Test                                            0000-00-00 00:00:00                                                          2007-05-05 12:07:20 admin                               2007-04-11 16:59:25 
    10000005    kib                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1           15                      0           Pathological Test                                                            2007-05-18  00:00:00                                                    2007-05-07 16:10:01                                     0000-00-00 00:00:00                                                                                                                                                                                                                                                                                                          
    10000007    benson                                                       5           16                      25          dftf                                                                                                                                                                                                                                                            0           0           0           Bacteriological Test           30000001    2007-04-16                                      2007-04-16  09:57:00    done        admin                               2007-05-11 08:54:12 admin                               2007-04-16 09:57:04                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

     

    If the above results are not what is required then what is required???????

  8. ;D maliary... I'd suggest that Barand would appreciate more than one tables worth of information.. more like all the tables that are described in the query and some test data for each table.
  9. This is pretty much the same as your original query Azu:

     

    SELECT count(*) FROM Z
        LEFT JOIN a ON Z.1 = a.1
        LEFT JOIN b ON Z.1 = b.1
        LEFT JOIN c ON Z.1 = c.1
    WHERE a.1 IS NULL AND b.1 IS NULL AND c.1 IS NULL
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.