If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-08, 08:14
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Query help

I have been trying to use application code to loop a tesult set with absolutely no luck whatsoever. I would like to know if it is possible using some fancy artsy fartsy sql to get this working.

The code below gives me my entire result set which is fine however I need one row for location_name, addr1, and city. All of the other attributes will have 1 and many rows associated with the location_name, city, etc.

Code:
SELECT
  t1.location_name
, t1.addr1
, t1.city
, t2.name
, t2.email
, t3.w_name
, t3.r_type
, t3.i_type
, t3.disposition
, t3.report
  FROM
    location AS t1
      Inner
        Join email AS t2 ON t1.location_id = t2.location_id AND t1.customer_id = t2.customer_id
      Left Outer
        Join report AS t3 ON t1.customer_id = t3.customer_id AND t1.location_id = t3.location_id
  WHERE t3.stamp >= date_sub(now(), interval 1 day) AND t1.customer_id = '1' AND t2.location_id = '66'
My desired first row output would look like:
Code:
location_name    addr1    city
somecustomer    1234..   Los Angeles
And the next row:
Code:
name    email    w_name    r_type    i_type    disposition    report
tom      a@d..   Jim W      gold       band      A                1
jane     w@f..   Pete        silver      band      A                0
And so on..

Can this be acomplished?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On