i have table called [Updated_SQLSOLD] with field name [Branch], [Barcode] and now i have 10 branches but not all branch has barcode
Example.
*[Branch] *[Barcode]
----------------------
branch1 | 25122225
branch2 | 25122225
branch3 | 25122225
branch4 | 25122225
branch5 |
branch6 |
branch7 |
branch8 | 25122225
branch9 |
branch10 |
SELECT [Branch], [Barcode] FROM [MHO_Report].[dbo].[Updated_SQLSOLD] where [Barcode] = '25122225'
Result - - is
*[Branch] *[Barcode]
----------------------
branch1 | 25122225
branch2 | 25122225
branch3 | 25122225
branch4 | 25122225
branch8 | 25122225
now how to display all branches even if no serial is available, like this
*[Branch] *[Barcode]
----------------------
branch1 | 25122225
branch2 | 25122225
branch3 | 25122225
branch4 | 25122225
branch5 | Null
branch6 | Null
branch7 | Null
branch8 | 25122225
branch9 | Null
branch10 | Null
Thanks
Use a self-JOIN for your table with a
LEFT JOIN
:Demo
Do not consider any condition in your select statement. Simply write :
Or if you want to have condition and also null values :
Your question is incomplete. Obviously the answer to your question so far is
But I'm guessing that you have other Barcodes that you want to exclude? So is the question "where my Barcode or Barcode is null"? So:
Or something else?
Hope this helps: