Jump to content

Advanced Find Guide/Manual (work in progress)


Recommended Posts


Here is a first draft of information about the Advanced Find. Let me know if something needs to be added, deleted, modified, or explained better.

********************************************

I believe the database currently used by CB is SQLite.

Here is a link to the SQL (Structured Query Language) for SQLite Select.

https://www.sqlite.org/lang_select.html

Here is a link to the Built-in Scalar SQL Functions

https://www.sqlite.org/lang_corefunc.html

Because of the limits put on Advance Find, a lot (most) of the SQLite documentation is of no use but it will get you the syntax for the ones you would use.

(NOTE: I am supplying these links in case they help someone. Personally, I would use them as examples of how NOT to write a manual. I know what I am doing with SQL and I find these (while accurate) are to read/follow.)

********************************************

The Query functionality in the Advanced Find is limited to just the WHERE clause.
You can't control the Select (what columns are returned), the From (the tables involved), or the Group By (used with Aggregate Functions like Sum, Count, Average, etc.). The main reason for this business decision is that every row returned has to be unique to allow them to be updated (changed) individually.

Below are sections that are explained in more detail below:

Data Types
Comparisons
Order By
Random Notes

********************************************

DATA TYPES:

To make it simple, there are just four Data Types (there are actually sub-types for some of these).

Text:

This is character data and can contain any alpha/numeric/special characters. All Text searches are case-insensitive (ignores case of letters). The constant compare value needs to be contained in single 'tick' marks (double 'tick' marks also work but single is the more standard way).

I.[Title] = 'batman'

This will return just the one Title 'Batman" as it is an exact match (and shows that Case doesn't matter)

Date:

This contains Date information. It has to be a valid date. (i.e. Feb 31, 2021 is NOT a valid date). Despite the display of the date in CB as m/d/YYY, the date in SQLite is in ISO standard format of YYYY-MM-DD. This is important because...

I.CoverDate = '2020-12-01' will return rows (assuming there is data with that value).
I.CoverDate = '12/1/2020'  will NOT return any rows.

Also it has to be an exact match as all the digits are important:

I.CoverDate = '2020-12-1' will NOT return any rows.

And like Text, Date constants need to be contained in single 'tick' marks.

Number:

This contains Numeric information (Integer or Decimal).

I.QtyInStock = 2
I.IssueNum = 0.5
I.IssueNum = -1

Binary:

This is represented by a Check-box. It is a True/False or 1/0 value. As you can see it has two states. Basically, it translates to 'Is Checked' or 'Is Not Checked'.

These are equivalent and will return rows where the CustomCheck2 check-box IS Checked

I.[CustomCheck2] IS True
I.[CustomCheck2] = 1

And, as you might guess, change to False or 0 to find if a check-box Is Not Checked.

********************************************

COMPARISONS:

When using the Where clause, you are normally comparing a Column value to a constant to find something. Some comparison operators are:

=      Equal To
<>   Not Equal To
<     Less Than
>     Greater Than
<=   Less Than or Equal To
>=   Greater Than or Equal To

These work as you would expect:

I.Title =  'Batman' (Finds Only exact match)
I.Title <> 'Batman' (Finds All except 'Batman')
I.Title <  'Batman' (Finds All from !Gag! (Harrier) to Baticomic)
I.Title >  'Batman' (Finds ALL from 'Batman & Robin (Panini Deutschland)' to '…One to Go')
I.Title <= 'Batman' (Same as < but also includes 'Batman')
I.Title >= 'Batman' (Same as > but also includes 'Batman')

BETWEEN:

Syntax is BETWEEN x AND y
It is inclusive (meaning the value of X and Y will be included in the results).
It is equivalent to using the >= and <= together. For example, these produce the same results:

I.IssueNum BETWEEN 5 and 10
I.IssueNum >= 5 AND I.IssueNum <= 10

Either of these will find all IssueNum values of 5, 6, 7, 8, 9, and 10 (assuming only integer values and the value exists).

Note: X has to be Less than (or equal) to Y for it to work. This is easier to see if you use the >= and <=

I.IssueNum BETWEEN 10 and 5 is equivalent to
I.IssueNum >= 10 and I.IssueNum <= 5
There can't be a value that is both Greater than 10 and Less than 5

IN:

Syntax is IN (value1, value2,...)
Searches for a list of possible value instead of just one.
It is equivalent to using multiple = comparisons. For example, these produce the same results:

I.IssueNum IN (5, 8, 25, 32) (Note: the values can be in any order)
I.IssueNum = 5 OR I.IssueNum = 8 OR I.IssueNum = 25 OR I.IssueNum = 32

Either will find all IssueNum values of 5, 8, 25 and 32.

IS:

This one is a little different it only has a couple formats:
IS True
IS False

It is mainly used for Binary Data Types.
(NOTE: there is also an IS NULL but that should rarely be needed. What is does is check to see if a column contains NULL. NULL is nothing. It is not a 'space' or an empty-string. Rarely, you may need it if a column in CB allows NULL and you need to find them.)

LIKE:

Syntax is I.Title LIKE 'Batman%'
This will find values but uses wild-card symbols to allow finding non-exact matches.
The wild-card values are Percent ( % ) and Underscore ( _ ) where a % represents zero to many characters and _ is one and only one character.
(NOTE: You can use multiple _ in a row to indicate a specific number of characters.)

Examples:

I.Title LIKE '%Batman%'
will find anything that contains 'Batman' in it
(NOTE: Just because % is at the beginning doesn't mean that there has to be something in from of 'Batman' in the Title.)

I.Title LIKE 'Bat%Man'
will find anything that starts with 'BAT' and ends with 'MAN' and may or may not have other values between them.

I.Title LIKE '_Batman'
will find anything that that starts with a single character before 'Batman'
(NOTE: There has to be a value as this will NOT return just 'Batman')

I.Title LIKE '_atman' (one underscore)
will return anything that starts with some single character and ends with 'atman' (i.e. 'Batman', 'Catman, 'Ratman')

I.Title LIKE '__man' (two underscores)
will return anything that starts with two characters and ends with 'tman' (i.e. 'Batman', 'Catman', 'Hitman', 'Ratman')

I.Title LIKE '______' (six underscores)
will return anything with 6 characters (i.e. '10 Gen','Action', Batman', 'Zordon', etc.)

(There are also some NOT versions, like NOT BETWEEN, NOT IN, and IS NOT but NOT logic is best left to Expert Advanced users (or insane ones...). Having said that, they can be useful on occasion so I am at least mentioning them)

Boolean Logic Expressions:

The Where clause uses Boolean Logic Expressions. Besides the more familiar operators (<, >, =, etc.), it also includes AND, OR, and NOT.
They are used to concatenate single comparisons into more complex comparisons. For the Where clause, the comparisons have to end up as TRUE to return rows.
With AND, all comparisons have to be True for the Where clause to evaluate as True and return a row.
With OR, at lest one comparison has to be True for the Where clause to evaluate as True and return a row.

Here is a list to show how this works (the values True and False are being used as the comparisons to emulate the result of comparisons):

AND- All have to be True:
'True'  AND 'True'  evaluates to TRUE , row returned.
'True'  AND 'False' evaluates to FALSE, row NOT returned.
'False' AND 'True'  evaluates to FALSE, row NOT returned.
'False' AND 'False' evaluates to FALSE, row NOT returned.

OR- At least One has to be True:
'True'  OR 'True'  evaluates to TRUE , row returned.
'True'  OR 'False' evaluates to TRUE , row returned.
'False' OR 'True'  evaluates to TRUE , row returned.
'False' OR 'False' evaluates to FALSE, row NOT returned.

This is also the case for more that two comparisons:

'True' AND 'True' AND 'True'  evaluates to TRUE,  row returned.
'True' AND 'True' AND 'False' evaluates to FALSE, row NOT returned

'True'  OR 'False' OR 'True'  evaluates to TRUE,  row returned.
'False' OR 'False' OR 'False' evaluates to FALSE, row NOT returned.

You can use both AND and OR in the same Where clause but you need to be aware of the Order of Precedence (the order the expressions are evaluated in).
AND is processed before OR. To make it easier on you, it is best to use Parenthesis to control the order the comparisons are done.
Consider this:

I.Title = 'Batman' OR  I.IssueNum = 2 AND I.Printing = 2  OR I.Variation = 'HC'
I.Title = 'Batman' OR (I.IssueNum = 2 AND I.Printing = 2) OR I.Variation = 'HC'

At first glance, the first one is hard to tell what is going to happen. The second one, with parenthesis, is what it actually being done.
With the parenthesis, it is easier to see that it will return Any Batman rows, along with Any rows with IssueNum 2 & Printing 2, along with Any rows that have a Variation of HC.
While it is still a complex query, it should be easier to understand what will happen.

Here is another similar comparison where the only difference is the ANDs and ORs:

 I.Title = 'Batman' AND I.IssueNum = 2  OR  I.Printing = 2 AND I.Variation = 'HC'
(I.Title = 'Batman' AND I.IssueNum = 2) OR (I.Printing = 2 AND I.Variation = 'HC')

Again, while both will return the same rows, with the parenthesis, it is easier to see that this will return Any Batman with IssueNum 2, along with Any row that has Printing 2 and Variation HC.

********************************************

ORDER BY:

There isn't much to say about the Order By clause. It pretty much does what you would expect. Sorts the resutls as requested.
The one thing not obvious is you can control the direction of the ordering with ASC (the default value) or DESC.

I.Title ASC would sort A-Z and/or 0-100 (ASC is the default and you don't need to add it)
I.Title DESC would sort Z-A and/or 100-0

You can mix and match the use of ASC and DESC
I.Title ASC, I.IssueNum Desc
I.Title Desc, I.IssueNum Desc, I.Variation ASC

Keep in mind the Data types when doing sorts. Number and Dates sort as you would expect. Text sorts characters from left to Right. If you have what looks like numbers in a Text field, the sort order would be  1, 10, 100, 2, 20, 200, etc. It would not be 1, 2, 10, 20, 100, 200.

The following will sort the results the same way (or at least very similar) to the way CB sorts its display:

I.Title, I.IssueNum, I.ItemType, I.Variation, I.Printing

********************************************

RANDOM NOTES:

What is Item # and why not to use it in Order By:

While Item # is the displayed value, it isn't the best field to do Finds with, in most cases.
Item # is composed of 4 other columns. They are, in order, ItemType, IssueNum, Variation, and Printing.

Item # 1/HC-2 is composed of:
ItemType: none used (or regular issue but don't try to find regular issue in ItemType as it is only a display item)
IssueNum: 1
Variation: HC
Printing: 2

If you try to use Item # in the Order by, it will sort all ItemTypes first. Also, Item # is a Text field and NOT a numeric. You will also get 1, 10, 100-109, 11, 110-119, 12, 120-...

This is why it is better to use the various components of the Item # instead of Item # itself when sorting to match CB order:

I.Title, I.IssueNum, I.ItemType, I.Variation, I.Printing

======

Use of [] in Column names:

Some of you may be curious what the brackets ( [] ) around column names are for (and why I don't use them).
If the creator of a Table use a column name with a space (i.e. 'Issue Number') then it is required to enclose it in brackets ( [Issue Number] ) when referencing it so the database sees it has a 'single' name. If there is no space (i.e. IssueNumber), then the brackets are optional. Since the SQL processor adding the columns doesn't know if there are spaces or it, it defaults using brackets, just in case. It doesn't hurt to have them and not need them.
However, to me, they just clutter up the display of the query (the less I have to look at and ignore, the better) so I never type them in when I write a query.
A similar point could be made for parenthesis. Most SQL processors put way too many, unnecessary parenthesis in their statement. Don't get me wrong. As I showed above, parenthesis can (and sometimes must) be used to make the query either easier to understand or do what you want. But the over-use of them can make for a cluttered query. (Okay, my pet peeve part of this manual is over (for now...))

======

How to use Publisher in Advanced Find:

One thing you may notice, is that only ISSUE columns are available in Advanced Find in the drop-down box. In the old days (pre CB 2020) there used to be "I" (Issue tables) and "T" (Title tables) where you could access Publisher in Advanced Find. The "I" and "T" were qualifiers to indicate which table a column is in.
---
Quick aside (geek alert)... The "I" in I.Title is the qualifier (or identifier) of a Table as defined in a From clause (since the From clause has not been displayed, you can see it directly). It is only really needed if you have more than one Table in the From and you Join them together (i.e. Issue table and Title table). The syntax would look like this:

From Issue_Table I inner join Title_Table T on I.Title = T.Title

The only thing you need to get from this is that the column Title is in both Tables. Because of this it needs to be qualified when reference (i.e. I.Title for the one int the Title_Table)
---
Sadly, with CB 2020, only "I" table columns are (readily) available.
However, there is a second way to qualify a column and that is with the actual Table name.
So, while you can't select Publisher from the drop-down box, you CAN use it by qualifying it with the actual table name like this:

ComicTitles.Publisher = 'Marvel'

NOTE: This is a non-supported feature which may or may not work in future releases of CB.
(Maybe HC will make Publisher available in the Advanced Find in the future (hint, hint, hint, please...?)

  • Like 3
Link to post
Share on other sites
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...