Your script is correct, it just means that customer table has same c_chinese values in multiple rows and they all match. Do you want to grab just a single random customer id if there are multiple matches?
sql searching problem
I have a excel to maintain a customer list with 2 column, 1 is english and another is chinese name,which contains 3
I have another table in database customer table. also with c_english, c_chinese name and customer ID.
I have create a temp table and then import all the data in excel into temp table.
and then match to the physical table customer by using below script.
I want to use temp table as a based to check.how many customer can be matched and find out the customer ID.
select c.cistomerid, temp.english , temp.chimese, c.c_english, c.c_chinese from temp left join customer c on temp.chinese =c.c_chinese
however, the total no. of record is not same as the number of record in temp table, why. (more then 3 record)
I would like to check how many record can be matched by chinese name column, if it can't be match then the customer ID should be null or blank. otherwise , output the customer id
what should I do? any script to provide me for reference.
2 answers
Sort by: Most helpful
-
-
LiHongMSFT-4306 26,791 Reputation points
2022-09-14T02:38:04.873+00:00 Hi @nononame2021
Try this code:SELECT T.english,T.chinese,MAX(C.CustomerID)CustomerID FROM Temp T left join Customer C on T.chinese =C.c_chinese GROUP BY T.english,T.chinese
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.