differentiating results of sql right join
        Posted  
        
            by Sourabh
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Sourabh
        
        
        
        Published on 2010-06-11T07:57:30Z
        Indexed on 
            2010/06/11
            8:02 UTC
        
        
        Read the original article
        Hit count: 203
        
mysql-query
Hi
I have a below SQL query
SELECT `User`.`username` , Permalink.perma_link_id, Permalink.locale, Permalink.title, DATEDIFF( CURDATE( ) , Permalink.created ) AS dtdiff, `TargetSegment`.segment_text, TargetSegment.source_segment_id ,TargetSegment.perma_link_id ,TargetSegment.created ,TargetSegment.updated,  DATEDIFF( CURDATE( ) , TargetSegment.updated ) AS datediff
FROM `users` AS `User` 
RIGHT JOIN perma_links AS `PermaLink` ON ( `PermaLink`.`username` = `User`.`username` ) 
RIGHT JOIN target_segments AS `TargetSegment` ON ( `TargetSegment`.`username` = `User`.`username` ) 
RIGHT JOIN source_segments AS `SourceSegment` ON ( `SourceSegment`.`source_detail_id` = `PermaLink`.`source_detail_id` ) 
LEFT JOIN source_details AS `SourceDetail` ON ( `SourceSegment`.`source_detail_id` = `SourceDetail`.`id` ) 
WHERE `TargetSegment`.`username` = "xxxx"
AND `TargetSegment`.`segment_text` <> ""
AND `Permalink`.`perma_link_id` = `TargetSegment`.`perma_link_id` 
AND `TargetSegment`.`source_segment_id` = `SourceSegment`.`id` 
AND `Permalink`.`source_detail_id` = `SourceDetail`.`id` 
ORDER BY `TargetSegment`.`updated` DESC 
LIMIT 0 , 10 
This SQL is fetching correct results for me.I want to identify from which table each row if from , to be specific which result is due to PermaLink table and which is from TargetSegment table.
is this achievable ?
© Stack Overflow or respective owner