WHERE condition is true but not all rows are returned? (SQLite db) - sql

When I try to use WHERE word = "a" there is only 1 row returned when in fact there are 2 rows with the word "a". As you can see in the second picture there is also another "a" with the id = 1. How can I query both of them?
Only 1 row is returned with WHERE word = "a"
There are actually 2 rows with for the word "a"
UPDATE: They actually have different length,
one 1 and the other 2.

Related

Marking repeating or both in corresponding cell based on the criteria

i have a sheet in excel which have two columns Col "A" & Col "B"
in col "A" i have values like 1,1,1 - 3 times & 2,2,2,2 - 4 times
and in col "B" i have yes, yes, yes corresponding to column A value 1,1,1 &
yes, no ,yes no corresponding to column "A" value 2,2,2,2 as shown in the image.
now i want to add some values in col "C" based on codition like
if col "A" 1,1,1 all values are yes in col "B" then put SOME TEXT LIKE "repeating" in Col "C" in front of every value of col"A"
and if col "A" 2,2,2,2 all values are different like yes, no, yes , no in col "B" then put SOME TEXT LIKE "both" in Col "C" in front of every value of col"A"
for example see below image.-
-it will check all the similar values in col "A" First suppose it will take "1" first then it will check its corresponding value in col "B" and it will keep on checking all of the values of "1" in col"B" if all values are "yes" then it will simply put "repeating" in col"C" in front of every "1"
-but again it will check for all the values of "2" in col"B" if all values are "yes" then it will simply put "repeating" in col"C" in front of every "2" but as you can see all values are not same in front of "2" some are "yes" and some are "no" in col"B" so if all values of "2" are not same in col "B" then it will put "both in col"C" in front of every "2"
i want to know is there any formula for doing this or vba code is needed . please help me regarding this.
If you have Excel 2016 you can use COUNTIFS nested in an IF like:
Countifs will count the values based on two criteria.
=IF(COUNTIF($A$1:$A$7,A1)=COUNTIFS($A$1:$A$7,A1,$B$1:$B$7,B1),"Repeating","Both")
You can nest a third condition like this:
=IF(B1="may be","Confirm",IF(COUNTIF($A$1:$A$9,A1)=COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1),"Repeating","Both"))
Explanation:
The formula consists of two conditional IFnested:
The first IF(B1="may be","Confirm" evaluates if B1 = "may be" when is
true it returns "Confirm".
when is false start the second IF to compare one condition:
COUNTIF($A$1:$A$9,A1) - Countsif function counts values in a range
based on one condition. In this case, the criteria are each cell in
column A and count how many times are this value in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1) - Countifs function counts
values in a range based on multiple conditions. In this case, it is
counting based on two criteria for each value in A and B.
Evaluating second conditional:
For C1:
COUNTIF($A$1:$A$9,A1) = 3 3 times the value (1) in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1) = 3 3 times the values (1) and (yes).
So, if 3 = 3 then "Repeating".
For C4:
COUNTIF($A$1:$A$9,A4) = 4 4 times the value (2) in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A4,$B$1:$B$9,B4) = 2 2 times the values (2) and (yes).
So, if 4 = 2 is false it returns "Both".

Compare two sheets using ID column

I am looking to do a comparison of 2 sheets in a workbook in Excel 2013. Due to the number of records VLOOKUP and other formulas have been slow so I thought I would try VB to see if this was a quicker solution.
What I would like to do is compare each record by ID and highlight and mismatches in red. Due to the column names and position being different, I would also like to do the cell comparison on each record by specifying the column names to compare against. Finally, I would like to total the mismatches for each column into a 3rd sheet.
For example:
Sheet 1:
ID Col1 Col2 Col3 Col4
1 1 1 1 1
2 2 2 2 1
3 3 3 3 3
4 4 4 4 4
Sheet 2:
DBID Col1 Col2 Field Col3
1 1 1 1 1
2 2 2 2 2
4 4 4 4 4
3 3 3 3 3
So in the above example I would only like to Col4 compared with Field column and only see the Field column for ID 2 highlighted as an error with ID records 3 and 4 ignored because they match and are just in different positions in the file.
I would normally sort on ID instead of picking out a particular ID, but conscious that there could be records missing which means the data would be misaligned.
At the moment I have found this code which will highlight the mismatches in red, but matches cell by cell without taking into consideration that the columns and records might not be in the same order.
Sub RunCompare() 'Call the compareSheets routine Call compareSheets("Sheet1", "Sheet2") End Sub
Sub compareSheets(shtBefore As String, shtAfter As String) Dim mycell As Range Dim mydiffs As Integer 'If current cell is not a date then proceed (else skip and go to next), then 'if not same as corresponding cell in sheet After, 'mark as yellow and repeat until entire range is used For Each mycell In ActiveWorkbook.Worksheets(shtAfter).UsedRange If Not IsDate(mycell) Then
If Not mycell.Value = ActiveWorkbook.Worksheets(shtBefore).Cells(mycell.Row, mycell.Column).Value Then
mycell.Interior.Color = vbRed
mydiffs = mydiffs + 1
End If End If Next 'Display a message box stating the number of differences found MsgBox mydiffs & " differences found", vbInformation ActiveWorkbook.Sheets(shtAfter).Select End Sub
I am assuming that the ID is unique.
You have basically two solutions, with and without macro.
With Macro Logic can be as follows :
Get the first (Unique) column of first sheet
Loop through the first (Unique) column and find the matching row in second sheet
Compare between cells in that row with the first row of first sheet
Repeat the same steps for all rows
Also do a check to see if both sheets have same number of rows and columns; and no rows are duplicated.
Non Macro Solution :
Use VLookup Function to lookup for the row matching the value and do an equal comparison formula in a new sheet as
=IF(Sheet1!B1=VLOOKUP(Sheet1!A1,Sheet2!A:Z,2,FALSE),"Same","Different")
Note that you will need to increment the row number and column name I have highlighted in first column of the third (Answer) sheet.
Once you have values, you can use conditional formatting to highlight Different to Red

How to compare a list of rows to another list of rows in Excel?

I am trying to figure out if there are any differences between a list of data with another. In order for a row of data to "match" with another row, the row must have the same values in their corresponding column. The rows themselves do not have to be in any particular order. In particular, I am dealing with a parts list, where there are part numbers, descriptions, etc. I am trying to figure out if any rows of data are different from rows of data from another list.
I found Compare two sheets using arrays, which may have the answer to my problem, but I am having trouble figuring out how to adapt to my code due to inexperience in Visual Basic.
I was able to get it to work for a single column of data, comparing one column of data from one sheet to another, but cannot get it to compare entire rows of data.
Here is an example of I want this to work:
Sheet 1 Sheet 2
Column 1 Column 2 Column 1 Column 2
Row 1 22a 33 11 11
Row 2 22a 33a 22a 33
Row 3 55 22b 55 23b
The code in the link will tell you what is not in sheet 1 but in sheet 2 and vice versa. In this example, I would like the code to tell me Sheet 1 Row 2 and Sheet 1 Row 3 are not in Sheet 2, and Sheet 2 Row 1 and Sheet 2 Row 3 are not in Sheet 1 (Sheet 1 Row 1 and Sheet 2 Row 2 match).
If that is ok by you, you can do it without VBA using the following formula:
={IF(IFERROR(MATCH(A1&"|"&B1;Sheet7!$A$1:$A$3&"|"&Sheet7!$B$1:$B$3;0);-1)=-1;"Unique";"")}
Assuming that each of your tables start in A1 (so that the tables with three entries span A1:B3), and entering this formula into C1 (and copying it down), press CTRL+SHIFT+ENTER when entering the formula to create an array formula, this will show the word "Unique" in column C if the pair in that row on that sheet is not in any of the row-pairs on sheet 2.
You can then use conditional formatting to highlight unique rows, filter on the tables to include only unique rows, or some other way of doing what you need.
NOTE 1: I have entered my numbers in Sheet6 and Sheet7 instead of 1 and 2. The formula written above goes into Sheet6.
NOTE 2: My language use ; instead of , as function separator, so if yours use , you need to change that.
NOTE 3: You will need to expand the ranges Sheet7!$A$1:$A$3 and Sheet7!$B$1:$B$3 if your set grows (this will happen automatically if new rows are inserted in between the old ones). The best is still probably to create named ranges for each of the 4 columns, exchange the references with those, and manage the named ranges instead of the formulas.
NOTE 4: If your data set contains the character "|", you need to change that as well, to match some character that you for sure do not have there.
Alternatively you could in column C on each cheet enter (assuming first entry in C1)
=A1&"|"&B1"
and copy this down, then run the solution from your copied example using that C column instead of on A1 and B1.

Apply Count formula in a Excel Row with conditions True/False

I have to apply a logical count formula on a column which contains some value. It contains identical and non-identical numbers.
What I want is a way to apply a formula to the next column which will lookup the whole column and decide on below condition:
whether A1=A2; if True, if A1=A3 and so on till it returns False (not equal value) then count all the true results in a row and reflect the value against the first cell.
Then if there was three match then it should reflect 3 against the first cell and the next two cells should be left blank. Below is the example column:
Numbers No of Days
47.76
-429.98
-429.98
-429.98
-1328.98
-1328.98
-1328.98
-833.32
-643.7
-1328.98
-580.26
-556.76
-556.76
-1181.78
-1139.99
-1124.49
-1103.59
-1103.59
-1091.39
-1048.94
-1048.94
-451.38
-451.38
-321
-321
438.5
477.5
698.76
795.93
795.93
804.83
What I want should be like below after formula:
Numbers No of Days
47.76 1
-429.98 3
-429.98
-429.98
-1328.98 3
-1328.98
-1328.98
-833.32 1
-643.7 1
-1328.98 1
-580.26 1
-556.76 2
-556.76
-1181.78 1
-1139.99 1
-1124.49 1
-1103.59 2
-1103.59
-1091.39 1
-1048.94 2
-1048.94
-451.38 2
-451.38
-321 2
-321
438.5 1
477.5 1
698.76 1
795.93 2
795.93
804.83 1
Please help guys as whatever I tried has failed here. Need some excel experts to share some advise or a resolve.
In Cell B2 use =IF(A2=A1,"",MATCH(0,--(A2=$A2:$A$50),0)-1) entered using ctrl+shift+enter
The if statement checks to see if the number is the same as the one above it and if it is it leaves the cell blank.
Inside the match statement --(A2=$A2:$A$50) returns an array of 0s (if the cell doesn't match A2) or 1s (if it does match). The match statement finds the first 0 in the array (the first number that doesn't match). Since this returns the place in the array that starts at the current row it will give the number of rows that match+1. We just need to subtract that 1 to get the number we need.

Check if "MAN_ABC_COMMENT_CHANGE" doesn't occurs in Column D

In Column A, it has ID and it is random.
Sometimes ID repeat 2 times, sometimes 10 times, it is different all the time.
I need to check if "MAN_ABC_COMMENT_CHANGE" doesn't occur.
If for example in image below for ID = 12345 in column D "MAN_ABC_COMMENT_CHANGE" never occurred, so in new sheet or somehow show that for id 12345 MAN_ABC_COMMENT_CHANGE never occurred.
I have over 5000 rows of data and over 1000 ID
One method...
1) set up a Pivot table of ID from the data
2) add a formula in B2 =countifs(Sheet2!A:A,A2,Sheet2!D:D,"MAN_ABC_COMMENT_CHANGE")
3) copy down (double click the bottom right of cell to autofill)
4) the rows with zero are the ones you want (can filter them as required)