Here's my query. It selects a list of ids from two tables across two databases. The query works fine.
select en.id, fp.blogid from french.blog_pics fp, french.blog_news fn, english.blog_news en where fp.blogid = fn.id and en.title_fr = fn.title and fp.title != ''
I only want to display rows where a en.id
occurs more than once
So for instance, if this was the current query result
en.id fp.blogid --------------- 10 12 12 8 17 9 12 8
I only want to query to show this instead
en.id fp.blogid occurrences ----------------------------- 12 8 2
To select last two rows, use ORDER BY DESC LIMIT 2.
If you want to insert more rows than that, you should consider using multiple INSERT statements, BULK INSERT or a derived table. Note that this INSERT multiple rows syntax is only supported in SQL Server 2008 or later. To insert multiple rows returned from a SELECT statement, you use the INSERT INTO SELECT statement.
You can concatenate rows into single string using COALESCE method. This COALESCE method can be used in SQL Server version 2008 and higher. All you have to do is, declare a varchar variable and inside the coalesce, concat the variable with comma and the column, then assign the COALESCE to the variable.
select en.id, fp.blogid, count(*) as occurrences from french.blog_pics fp, french.blog_news fn, english.blog_news en where fp.blogid = fn.id and en.title_fr = fn.title and fp.title != '' group by en.id having count(*) > 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With