You’re doing two complete table scans for that, and the SELECT * on both is not helping your cause, epecially if the tables are large. You could use a left outer join instead (the WHERE clause shows the NON matches).
SELECT A.Field1
, A.Field2
FROM A.city A
LEFT OUTER JOIN B.City B ON A.name = B.name
WHERE B.name is NULL
if this is a one-off query (i.e. you won’t be doing it on a regular basis), then clone the B table, update the name column, put an index on it, and use that in your query
Apparently you didnt read the OP’s post. See how the OP said rows and not columns? I would think at your skill level you could tell the difference and know what the OP is talking about. The SQL the OP posted is more than clear he is comparing DATA. So the question still stands, OP why do you have duplicate data?
I didn’t say the o p is looking for duplicate rows and neither did he. He is asking to show data that is in one table and not in another which means there can be duplicates. Also, the fact that there are two tables with a name column which would likely be a city name since it is in the city table says either his database is not normalized or he has some special case that he hasn’t mentioned yet. It would be best for the Op to tell us what the actual problem is he is trying to solve rather than asking us about his attempted solution to the problem.
Maybe we should simply ask OP why he needs this query instead of guessing what het ment. I’m arround since about 2011 but I increasingly get the feeling that so-called profesionals want to prove to each other how good they are, rather than what it really is all about at Sitepoint. Helping people who need help
I agree and in order to properly help the OP’s we need to know what the actual problem is they are trying to solve. Most often they ask for help on their attempt at solving the problem without telling us what the actual problem is.