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 > Please Help on a Join Query!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-10, 04:23
sysenm sysenm is offline
Registered User
 
Join Date: Oct 2010
Posts: 12
Please Help on a Join Query!!!

Hi All,


I have a table with following structure;

Table 1
---------------------------------------------------------------
ID | Zone | Area | Indicator | Value | Timestamp | Collector_ID
----------------------------------------------------------------


Collector_ID is a foreign key from another table of the following structure;
Table 2
----------------------------------------------------------------------------
ID | Collector_Name | Filename | Collection_Time | Added_at
----------------------------------------------------------------------------



I am trying to write a join query that will give me all the records from table 1 joining it with table two where collector_name contains "Agent_A" or "Agent_B.

Here is what i have been trying with:


select * from table_1 as one
inner join
table_2 as two
on one.collector_id = two.id

where
two.collector_name like %Agent_A% or
two.collector_name like %Agent_B% ;



Please help me to find errors or guide me if I am completely wrong.

Thank you very much!

Last edited by sysenm; 11-10-10 at 05:11.
Reply With Quote
  #2 (permalink)  
Old 11-10-10, 05:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by sysenm View Post
Please help me to find errors
you know, the best way to find the errors is to actually run the query and see what happens
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-10-10, 08:34
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
Quote:
I am trying to write a join query that will give me all the records from table 1 joining it with table two where collector_name contains "Agent_A" or "Agent_B.
Based on your description sounds like you would want to use a LEFT OUTER Join.

Dave
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