Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL procedure find 4 matching fields from 5
    primarykey
    data
    text
    <p>I am trying to write an sql procedure to identify rows that match on 4 out of 5 columns. Here's an example table:</p> <pre><code>CREATE TABLE [dbo].[Match]( [ID] [int] NULL, [col1] [nchar](10) NULL, [col2] [nchar](10) NULL, [col3] [nchar](10) NULL, [col4] [nchar](10) NULL, [col5] [nchar](10) NULL, [match] [nchar](10) NULL ) ON [PRIMARY] INSERT INTO dbo.Match VALUES ('1','A','A','A','A','A', null) INSERT INTO dbo.Match VALUES ('2','A','A','A','A','B', null) INSERT INTO dbo.Match VALUES ('3','A','A','A','B','A', null) INSERT INTO dbo.Match VALUES ('4','A','A','B','B','A', null) INSERT INTO dbo.Match VALUES ('5','A','B','A','B','A', null) </code></pre> <p>so the procedure should identify that rows 1,2 and 3 have 4 identical field values and row 3 has 4 4 identical field values to row 4 and 5.</p> <p>I tried joining the table to itself and then joining on 4 fields, then doing this for every combination but it doesn't quite do what I want. Any advice would be greatly appreciated.</p> <p>Thanks for replying, I should have been a bit clearer.</p> <p>I need to know that rows 1,2,3 have four field values in common (The A's and B's) and that rows 3,4,5 have four field values in common, then either update a field in that table to record this (so for example write 'group1' to a field for rows 1,2,3 and the same for rows 3,4,5 but when a row is in two groups it might be best to write to another table and add a row to record the matches)</p> <p>I have full control of the schema so can do what I need to.</p> <p>So I don't need to know the number of matches for each row, but record the groups if you like in which all members of the group have four fields in common.</p> <p>thanks again CM</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload