I have written an application to manage my home library. It has a table for Books and a table for Works and a many to many table to link them. Each Book can contain multiple Works and each Work can appear in multiple Books. Each of Books and Works has a Title.
I want a query that returns a list of ID and Title for all those Books that has an (input) string contained in the Book Title or Work Title.
Current implementation gives two or more entries if Book contains two or more Works that contain the string. I assume I have to Group but can't get the syntax right.
Currently setting the rowsource for the list on an Access form to be:
SELECT QBW.ID, QBW.Title, QBW.WorkTitle
FROM qryBookOrWork AS QBW
WHERE ((QBW.Title LIKE 'civil') OR (QBW.WorkTitle LIKE 'civil'))
Don't know how to Group (if that is required)
This produces two copies of Uncivil Wars because that book contains two Works (and the Book contains the string 'civil') giving two rows in QBW.
After writing this I had the thought that I could 'wrap' the current query in a "SELECT DISTINCT QBW.ID, QBW.Title FROM ( )"
and it seems to work!
Related
I want user to select several categories in categorized view by mouse left-click, so I can write a script to print documents that belongs to different categories without selecting every document.
I have to get selected categories names by lotusscript. Is it possible?
I can get one category name:
Dim ws As New NotesUiWorkspace
Dim uiView as NotesUiView
Set uiView = ws.CurrentView
Dim category As String
Set category = uiView.CaretCategory
But how can I get several categories names, if user selects more than one category?
screen example
Simple answer: you can‘t...
unfortunately there is no way at all to get selected categories, neither by LotusScript not by any other means..
the most you can get is a NoteId... but although it increases when selecting categories further down the view there is no way to map this random id to a real category. I tried for weeks and weeks and used any trick I can think of (and there are a lot of them, as I work with Notes / Domino since 25 years now), but I could not find any workaround.
Sorry to say: you are stuck with this approach... you could show a dialog form with a #DbColumn() on the categorized column and let the user select from a DialogList item or whatever pleases you. But selecting / identifying more than one category in a view is not possible (unless you select the documents belonging to the categories and read the values from them).
As far as I know, this isn't possible in the Notes client, though you could do it with a custom web interface.
There are no officially documented APIs to get all selected categories in Notes.
NotesUIView.CaretCategory, which you have in your code, only gets the category for the selection rectangle, so it only works for a single selection.
I'm using Tableau to show some schools data.
My data structure gives a table that has all de school classes in the country. The thing is I need to count, for example, how many schools has Primary and Preschool (both).
A simplified version of my table should look like this:
In that table, if I want to know the number needed in the example, the result should be 1, because in only one school exists both Primary and Preschool.
I want to have a multiple filter in Tableau that gives me that information.
I was thinking in the SQL query that should be made and it needs a GROUP BY statement. An example of the consult is here in a fiddle: Database example query
In the SQL query I group by id all the schools that meet either one of the conditions inside de IN(...) and then count how many of them meet both (c=2).
Is there a way to do something like this in Tableau? Either using groups or sets, using advanced filters or programming a RAW SQL calculated fiel?
Thanks!
Dubafek
PS: I add a link to my question in Tableu's forum because you can download my testing workbook there: Tableu's forum question
I've solved the issue using LODs (specifically INCLUDE and EXCLUDE statements).
I created two calculated fields having the aggregation I needed:
Then I made a calculated field that leaves only the School IDs that matches the number of types they have (according with the filtering) with the number of types selected in the multiple filter (both of the fields shown above):
Finally, I used COUNTD([Condition]) to display the amounts of schools matching with at least the School types selected.
Hope this helps someone with similar issue.
PS: If someone wants the Workbook with the solution I've uploaded it in an answer in the Tableau Forum
So, basically, I have two tables called "dadoscatalogo" and "palavras_chave", with a common field, "patrimonio" which is the primary key of "dadoscatalogo".
I'm using a servlet to connect to the database with these tables, and passing a query to search for entries based on some search criteria that's defined by the user.
Now, since the user can search for entries based on information present in both tables, I need to do an INNER JOIN, and then use WHERE to search for that info. I'm also using LIKE, because the user may pass just part of the information, and not all of it.
So, to test it all out, I tried passing it a few parameters to work with, and see how it went. After some debugging, I found out that there was some mistake in the query. But I can't seem to be able to point out exactly what it is.
Here's the test query:
SELECT dadoscatalogo.patrimonio
FROM dadoscatalogo
INNER JOIN palavras_chave
ON dadoscatalogo.patrimonio=palavras_chave.patrimonio
WHERE dadoscatalogo.patrimonio LIKE '%'
AND dadoscatalogo.titulo LIKE '%tons%'
OR palavras_chave.palchave LIKE '%programming%';
So, basically, what I'm trying to do with this query is, get all the primary keys from "dadoscatalogo" that are linked to a record with a "titulo" containing "tons", or a "palchave" containing "programming".
PS. Sorry for the names not being in English, hopefully it won't be too much of a distraction.
EDIT: Right now, the tables don't have much:
This is the dadoscatalogo table:
http://gyazo.com/fdc848da7496cea4ea2bcb6fbe81cb25
And this is the palavras_chave table:
http://gyazo.com/6bb82f844caebe819f380e515b1f504e
When they join, I'm expecting it to have 4 records, and it would get the one with patrimonio=2 in dadoscatalogo (which has "tons" in titulo), and the one with palchave=programming (which would have patrimonio=1)
As per my understanding run below query:
SELECT dadoscatalogo.patrimonio
FROM dadoscatalogo
INNER JOIN palavras_chave
ON dadoscatalogo.patrimonio=palavras_chave.patrimonio
WHERE dadoscatalogo.titulo LIKE '%tons%'
OR palavras_chave.palchave LIKE '%programming%';
So, I'm practicing for an exam (high school level), and although we have never been thought SQL it is necessarry know a little when handling MS Access.
The task is to select the IDs of areas which names does not correspond with the town's they belong to.
In the solution was the following example:
SELECT name
FROM area
WHERE id not in (SELECT areaid
FROM area, town, conn
WHERE town.id = conn.townid
AND area.id = conn.areaid AND
area.name like "*"+town.name+"*");
It would be the same with INNER JOINS, just stating that, because Access makes the connection between tables that way.
It works perfectly (well, it was in the solution), but what I don't get is that why do we need the "not in" part and why can't we use just "not like" instead of "like" and make the query in one step.
I rewrote it that way (without the "not in" part) and it gave a totally different result. If I changed "like" with "not like" it wasn't the opposite of that, but just a bunch of mixed data. Why? How does that work? Please, could someone explain?
Edit (after best answer): It was more like a theoretical question on how SQL queries work, and does not needed a concrete solution, but an explanation of the process. (Because of this I feel like the sql tag however belongs here)
One thing that would create a difference is to consider this example
areaid areaname townname
1 AA AA
1 AA BB
So your first query would exclude both records from the outcome. Because the inner query would identify areaid =1 to be among those to be excluded. Therefore, both records will not show up in the output.
Using not like however would exclude the first record and return to you the second record. Because the first record satisfies the condition with not like but the second doesn't satisfy the condition.
In other words, the first query would exclude any area (and corresponding records) that have at least one townname that is like an areaname. The second approach, would exclude only incidences where areaname is like townname but doesn't necessarily exclude all records for that area.
The reason is because there can be more than one town in an area, right?
So if there is a town in an area that has a similar name, then that area will be found in the LIKE subquery.
If there is another town in the SAME AREA that does not have a similar name, then that area will ALSO be found in the NOT LIKE subquery.
So the same area can be returned whether you use LIKE or NOT LIKE, because of the one-to-many relationship to towns.
Make sense?
It depends on what the relationship between area, town and conn are. If you have many towns in an area, you will see the area duplicated in your row set. Your original query simply asks "Show me the areas that are in the following list:". Your query in one-step asks a different question: "Show me the 'conns' in towns, in areas which have an area name not like the town name...
SELECT name
FROM area, town, conn
WHERE area.id = conn.areaid
AND town.id = conn.townid
AND area.name NOT like "*"+town.name+"*");
I'm developing a website with a custom search function and I want to collect statistics on what the users search for.
It is not a full text search of the website content, but rather a search for companies with search modes like:
by company name
by area code
by provided services
...
How to design the database for storing statistics about the searches?
What information is most relevant and how should I query for them?
Well, it's dependent on how the different search modes work, but generally I would say that a table with 3 columns would work:
SearchType SearchValue Count
Whenever someone does a search, say they search for "Company Name: Initech", first query to see if there are any rows in the table with SearchType = "Company Name" (or whatever enum/id value you've given this search type) and SearchValue = "Initech". If there is already a row for this, UPDATE the row by incrementing the Count column. If there is not already a row for this search, insert a new one with a Count of 1.
By doing this, you'll have a fair amount of flexibility for querying it later. You can figure out what the most popular searches for each type are:
... ORDER BY Count DESC WHERE SearchType = 'Some Search Type'
You can figure out the most popular search types:
... GROUP BY SearchType ORDER BY SUM(Count) DESC
Etc.
This is a pretty general question but here's what I would do:
Option 1
If you want to strictly separate all three search types, then create a table for each. For company name, you could simply store the CompanyID (assuming your website is maintaining a list of companies) and a search count. For area code, store the area code and a search count. If the area code doesn't exist, insert it. Provided services is most dependent on your setup. The most general way would be to store key words and a search count, again inserting if not already there.
Optionally, you could store search date information as well. As an example, you'd have a table with Provided Services Keyword and a unique ID. You'd have another table with an FK to that ID and a SearchDate. That way you could make sense of the data over time while minimizing storage.
Option 2
Treat all searches the same. One table with a Keyword column and a count column, incorporating SearchDate if needed.
You may want to check this:
http://www.microsoft.com/sqlserver/2005/en/us/express-starter-schemas.aspx