I have Two Tables Where i am match table 1 data with table 2 data. How i can get the data from left table and no matching record from right table means if any match found in the right table i need to omit that and the remaining value as a result
            Asked
            
        
        
            Active
            
        
            Viewed 4,020 times
        
    -1
            
            
        - 
                    Possible duplicate of [What is the difference between "INNER JOIN" and "OUTER JOIN"?](https://stackoverflow.com/questions/38549/what-is-the-difference-between-inner-join-and-outer-join) – philipxy Aug 20 '18 at 21:54
- 
                    You don't say what the result looks like in rows with "no matching record from right table". PS This is a faq. Please always google many clear, concise & specific versions/phrasings of your question/problem/goal & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using use one variant search for your title & keywords for your tags. Yet you have *tagged* this with outer-join so why do you have to ask a question. What exactly do you not understand? – philipxy Aug 20 '18 at 21:57
4 Answers
1
            
            
        Try below query with left join and given condition of righttable.id is null - this will give you non matching rows
select * from lefttable left join righttable on lefttable.id=righttable.id
    where righttable.id is null
 
    
    
        Fahmi
        
- 37,315
- 5
- 22
- 31
1
            
            
        SELECT *
FROM L_TABLE L
LEFT JOIN R_TABLE R 
 ON L.id=R.id
WHERE R.id IS NULL
 
    
    
        Prahalad Gaggar
        
- 11,389
- 16
- 53
- 71
1
            
            
        SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.common_field = table2.common_field;
 
    
    
        Zaynul Abadin Tuhin
        
- 31,407
- 5
- 33
- 63
 
    
    
        ahmad izhar
        
- 150
- 1
- 13
- 
                    
- 
                    first you will get the field from table1 which has matching property to the table 2. e.g table1. field that exists in table2 column. – ahmad izhar Aug 20 '18 at 06:54
- 
                    SELECT Customers.CustomerName, Orders.OrderID FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName; – ahmad izhar Aug 20 '18 at 06:57
- 
                    @ahmadizhar this code won't give the wanted result. It would also return the rows that exist in table 2. – Goran Kutlaca Aug 20 '18 at 07:19
- 
                    if you want to just just unselect the data from table2 you may use then simple query using where clause like -> whereNotIn('table2.coloumn' ','=', $variable having id of table 1); hope you got it, pardon any mistake ! – ahmad izhar Aug 20 '18 at 07:42
0
            
            
        use left join with right table column in where condition
    select t1.* from table1 t1 left join table2 t2 on t1.id=t2.id
   where t2.id is null
 
    
    
        Zaynul Abadin Tuhin
        
- 31,407
- 5
- 33
- 63
