Click here to Skip to main content
15,799,398 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to get an output username, email, statename, districtname but getting an error

am writing query for inner joins.

What I have tried:

from userprofiledetails 
inner join state_info
on userprofiledetails.stateid=state_info.stateid
inner join districtinfo on 
Updated 22-Jan-23 19:02pm
Sandeep Mewara 22-Jan-23 21:39pm    
You have shared SQL query but error seems to be with your programming code. It clearly states the reason to - seems your conversion is failing from varchar to int as one of the values retrieved from DB is not integer. You need to handle the usecases correctly.

I would guess field values that are either NULL or space could be first possibile culprit.

1 solution

First, we're going to rewrite the statement so it's a bit easier to read:
SELECT upd.username
     , si.statename
     , di.districtname
FROM userprofiledetails AS upd
INNER JOIN state_info AS si ON upd.stateid = si.stateid
INNER JOIN districtinfo AS di ON upd.districtid = di.districtname

Now, take a look at your second INNER JOIN:
INNER JOIN districtinfo AS di ON upd.districtid = di.districtname

The error is complaining that you're trying to equate a "districtname" to a "districtid".
It's telling you that you cannot convert the name to an integer to join the records in both tables.

So what do you think that join should really look like?
INNER JOIN districtinfo AS di ON upd.districtid = di.district??
Share this answer
GKP1992 23-Jan-23 1:08am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900