I have a table that allows records to be inserted which are very similar but differ by a single column value or two. For example the following records are in the table:
ID TITLE URL COUNTRY
1494 Hollywood Reporter http://www.hollywoodreporter.com USA
1497 Hollywood Reporter via Drudge Report http://www.hollywoodreporter.com NULL
2158 Hollywood Reporter via http://www.hollywoodreporter.com NULL
I would like to update the country column in the last two records where the url is the same. Also I would also like to know how to sort my table by url column so that all duplicate urls are grouped together or even if they are similar as you have in some cases like:
http://www.hollywoodreporter.com http://www.blog.hollywoodreporter.com
Thanks in advance.
Tried the following and it worked where the urls were the same
UPDATE t1
SET t1.country = t2.country FROM Sources AS t1 JOIN sources AS t2 ON t1.url = t2.url WHERE t1.url= t2.url;
just got to figure out the rest. thanks everyone
UPDATE
I was able to edit the records that had matching urls but for the ones that are similar like http://www.pantagraph.com http://pantagraph.com http://pantagraph.com/titles
were not updated. When using the sort and select I can view all these records but when trying to update them it does not work. I even just tried this simple version of:
select * from Sources s
where s.url like url
which shows the records but when updating it did not work.
update Sources
set country = s.country
from Sources s
where s.url like url