SQL Server · CrudLabDB

Merge two articles

Feature 9. The article you keep gets the combined data; the other one goes to the trash and remembers merged_into_id, so nothing is lost.

2 × UPDATE in one transaction
1 · Choose the articles
Pick two articles to compare

Tip: tick two rows in the list and press Merge. Try "Lambda expressions cheat sheet" with its second copy.

SQL behind this page

Captured by a Hibernate StatementInspector and by the JdbcTemplate code. ? marks a parameter: values are sent separately, which keeps SQL injection out.

Loading this page
1
SELECT
  COUNT(*)                                                                AS total,
  SUM(CASE WHEN deleted = 0 AND archived = 0 THEN 1 ELSE 0 END)           AS active,
  SUM(CASE WHEN deleted = 0 AND archived = 0 AND status = 'DRAFT' THEN 1 ELSE 0 END)       AS drafts,
  SUM(CASE WHEN deleted = 0 AND archived = 0 AND status = 'PUBLISHED' THEN 1 ELSE 0 END)   AS published,
  SUM(CASE WHEN deleted = 0 AND archived = 0 AND status = 'UNPUBLISHED' THEN 1 ELSE 0 END) AS unpublished,
  SUM(CASE WHEN deleted = 0 AND archived = 0 AND pinned = 1 THEN 1 ELSE 0 END)    AS pinned,
  SUM(CASE WHEN deleted = 0 AND favourite = 1 THEN 1 ELSE 0 END)                  AS favourites,
  SUM(CASE WHEN deleted = 0 AND archived = 0 AND is_read = 0 THEN 1 ELSE 0 END)   AS unread,
  SUM(CASE WHEN deleted = 0 AND locked = 1 THEN 1 ELSE 0 END)                     AS locked,
  SUM(CASE WHEN deleted = 0 AND archived = 1 THEN 1 ELSE 0 END)                   AS archived,
  SUM(CASE WHEN deleted = 1 THEN 1 ELSE 0 END)                                    AS trash
FROM article
2
select a1_0.id,a1_0.archived,a1_0.archived_at,a1_0.category,a1_0.code,a1_0.content,a1_0.created_at,a1_0.deleted,a1_0.deleted_at,a1_0.favourite,a1_0.locked,a1_0.locked_at,a1_0.locked_reason,a1_0.merged_into_id,a1_0.pinned,a1_0.pinned_at,a1_0.priority,a1_0.published_at,a1_0.is_read,a1_0.read_at,a1_0.row_version,a1_0.source_id,a1_0.status,a1_0.summary,a1_0.tags,a1_0.title,a1_0.updated_at from article a1_0 where a1_0.deleted=0 and a1_0.archived=0 order by a1_0.title offset ? rows fetch first ? rows only