---
title: "SQL Mach two table"  
description: "SQL Mach two table"  
author: "Anonymous User"  
published: 2013-07-09  
updated: 2013-07-09  
canonical: https://www.mindstick.com/forum/1278/sql-mach-two-table  
category: "mysql"  
tags: ["mysql"]  
reading_time: 1 minute  

---

# SQL Mach two table

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I've 2 table.\
Table1\
Has [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) about 2700 rowsColums: ID, NO, [NAME](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)Table2:\
Has count about 300 rowsColums: ID, NAMEwhere:\
Table1.NO = Table2.IDI want to list Table1(2700 rows) but if Table1 doesn't contain some of Table2's rows I want to write "NA"\
How can i do that with SQL.\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi,\
I assume you want to output the Name from table2, if it's present, in which case:\
SELECT a.id, isnull(b.name, 'NA'), a.nameFROM table1 aLEFT JOIN table2 b ON a.no = b.idwill do it for you (I've also output the id and name from table1).\
**EDIT:**\
Apologies, I didn't see the MySQL tag until I posted. You will need to use the coalesce function instead if isnull, like so:\

```
SELECT     a.id,    coalesce(b.name, 'NA'),    a.nameFROM    table1 aLEFT JOIN    table2 b    ON    a.no = b.id
```


---

Original Source: https://www.mindstick.com/forum/1278/sql-mach-two-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
