LIKE query with a varying number of LIKE’s - sql

My current test revolves around a hypothetical database consisting of a PERSON table populated with their details.
I can undertake a simple LIKE query were I return the details of say a person or persons named Tom.
My question is how can I build a query were there may be multiple names and return their details?
I my exercise there is a checkbox list of names and I need to return the details for all those I select?
Thank you in advance for your assistance.

Related

Tableau count values after a GROUP BY in SQL

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

MS Access & Queries

Looking for a bit of help for an Access/Query question pertaining to a homework assignment that has 6 separate questions. I have completed all but one. The assignment wants me to do the following query.
The name, unit price, and quantity ordered for all products purchased by a customer whose id is entered from the keyboard.
Is there a function I'm overlooking for the ID entity criteria? I've looked and searched but cannot find how to add that part into the query. Thanks in advance for any help.
You can accomplish this by making the ID criteria a parameter. Access will then pop up an input form that lets you enter the value of the parameter.
You can read more here and here.

Merging SQL views [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am working for the IT Department of a college as a student worker and have very limited knowledge in using SQL (I am not majoring in Computer Science/Engineering). I'll try my best to describe what I want to accomplish here.
I want to create a table that includes info about new students, basically : id, first name, last name, need exams (Y/N), Course101 section, instructor.
My problem is, exchange and transfer students and also some first year students would not have to/did not sign up for Course101, so using WHERE studnt_course = 'Course101%' will leave out those students. I would like to pick up those students in my view and display their Course101 section, Instructor values as Null.
I am thinking about making two views, one for all new students, and one for students with Course101 only, and do some kind of merging/union but not sure how to actually do that.
Any help will be greatly appreciated!
It's still a bit vague what the current tables actually look like which makes it hard to give a good suggestion.
Based on what you've given us I'd suggest looking into a LEFT INNNER JOIN which would put NULL where the two tables don't overlap.
If you are interested in learning database design (rather than just solving this particular problem) I'd suggest looking into proper database design.
Create two queries. One for the 101 students and one for the overseas/transfers (you will need to work out what the WHERE clause if for that)
Get each one working to your satisfaction.
If every thing is the same apart from the WHERE clause then:
Then grab the conditions for each, wrap them in brackets and put an OR in between, put that into one query
So something like:
SELECT Name, Id,ShoeSize
FROM Students
WHERE (studnt_course = 'Course101%') OR (transferred = 1 OR is_exchange = 1)
i.e., So all students WHERE <this> OR <that> is true
Other wise (e.g., using diffrent tables):
Make sure that you are selecting the same column names in you SELECT statement
If one column has the same info but is call some thing different you can go:
<columnName> AS <NameYouWantToCallIt>
Make sure the column names are in the same order.
Then put the word UNION in-between the two queries.
This will combine the results from both queries (and remove duplicates).
SELECT Name, Id, ShoeSize
FROM Students
WHERE studnt_course = 'Course101%'
UNION
SELECT Name, Id, FootSize AS ShoeSize
FROM exchangeStudents
WHERE transferred = 1 OR is_exchange = 1

SQL IN statement "inclusiveness"

I'm not a programmer, but trying to learn. I'm a nurse, and need to pull data for medical referral tracking from a database. I have a piece of GUI software which builds JOIN queries for me to pull things from the database. One of the operators I can use in the drop-down is "IN." The referral documentation is stored in the table as codes made up of one to three letters. For example, the code for a completed dental referral is CDF, and the code for a dental referral is D.
I want to build a report to allow other nurses to pull all their outstanding referrals, so I'll want to pull "D" but not "CDF"
If I use IN as the operator, and set my parameters to 'S','D','BP' {etc} will that also pull the records which have the other, longer codes which contain those same letters? (like CDF, CSR, CBP)
I don't want to test it because I only have access to the production database, and I don't want to hose up actual patient records. Thanks in advance for any help!
Assuming that the column that holds the referral code holds one and only one code per record (which is what it sounds like) the query should function as you want and will not attempt to match substrings.
In any event, there's no danger that a query in the form IN ('S', 'D', 'BP') will match substrings. To perform substring matches in SQL you have to use the LIKE operator.
The situation in which this will not work is if the referral code column holds multiple codes separated by commas. This is an all-too-common mistake in designing databases but if the product you're using is commercial rather than home-grown, I think it's very unlikely to be the case. If it is, searching it is much more difficult.

what is the best way to record users searches and count how many times it has been queried?

I am not sure what SQL is exactly, databases I think, would SQL be the thing to use?
I want it so that when a user types into a search box it displays a "did-you-mean" box, that also shows how many other people used that term but I will do later ;)
currently I just want the text to be saved into database (?) and also how many times it's been done.
(new to stackoverflow so sorry if format/whatever is bad)
You just need a three table named something like search_queries which has columns for: id, search_text, and count. Everytime somebody searches just increment the count column where search_text is equal to what they searched for. This is a really broad question though and you need to start by learning the basics and report back here with more specific questions.