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 > Help with query, if value in another table...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-22-11, 18:43
tjones1105 tjones1105 is offline
Registered User
 
Join Date: Dec 2007
Posts: 21
Help with query, if value in another table...

Hello,
I've been at this for a while so I decided to finally ask. If I have a select statement and I want one of the select columns result to be a BOOL/Int if the value is in another table?

For Example:

select cci.hostname, cci.client_group, cci.patch_group, cpsv.patch
From client_patch_status_view cpsv
Join ClientCheckIn cci on
cpsv.client_id = cci.client_id
AND patch like 'mySimplePatch-1.0'

Now, I want to add a column to the results called "inPatchGroup" to see if the "patch" is in the patch group patches table "patchgroup_patches".

How can I do this?

Thanks,
tom
Reply With Quote
  #2 (permalink)  
Old 02-22-11, 23:13
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Code:
SELECT cci.hostname
     , cci.client_group
     , cci.patch_group
     , cpsv.patch
     , CASE WHEN EXISTS
                 ( SELECT 'booyah'
                     FROM patchgroup_patches
                    WHERE patch = cpsv.patch )
            THEN 1 ELSE 0 
        END AS inPatchGroup
  FROM client_patch_status_view AS cpsv
INNER
  JOIN ClientCheckIn AS cci 
    ON cci.client_id = cpsv.client_id 
 WHERE cpsv.patch like 'mySimplePatch-1.0'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-24-11, 10:19
tjones1105 tjones1105 is offline
Registered User
 
Join Date: Dec 2007
Posts: 21
This worked great, thank you very much!
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