Can not show data from the script

derek chan 1 Reputation point
2022-08-16T02:24:29.917+00:00

I use the below command , it works fine to output data

SQL> SELECT table1.documentid FROM table1
documentid
001
002
003

While when use the below script
SELECT table1.documentid FROM table1
join table2
on table2.id=table1.documentid ;

the output is "no rows select"

I am wonder why no data will be output , what will be the possible reason of my error ?

really thanks for help

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,690 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

2 answers

Sort by: Most helpful
  1. CosmogHong-MSFT 22,781 Reputation points Microsoft Vendor
    2022-08-16T06:05:54.79+00:00

    Hi @derek chan

    the output is "no rows select"

    That's because the id column of Table 2 doesn't have data that matches the documentid column of Table 1, so 'no rows select'.
    As shown in this image:
    231383-image.png

    If you want the customerid in Table 1 to always be displayed,then you could try Table1 LEFT JOIN Table2
    Refer to this doc for more information.

    Best regards,
    LiHong

    0 comments No comments

  2. derek chan 1 Reputation point
    2022-08-16T06:22:58.827+00:00

    thanks reply ,

    if the Table2 have the below data , what will be the output ?

    Table2
    id
    001
    002