Microsoft Access ? wildcard showing blank return - ms-access

SELECT prod_id, prod_name
FROM Products
WHERE prod_name LIKE '?? inch teddy bear';
This is the code, it should return:
12 inch teddy bear
18 inch teddy bear
Instead I get nothing. New to SQL, go easy on me.

If you want to find the substring ?? inch teddy bear inside of a larger string, then you may add * wildcard markers to your LIKE expression:
SELECT prod_id, prod_name
FROM Products
WHERE prod_name LIKE '*## inch teddy bear*';

Related

Is it possible to run 2 Where Clauses for Different Columns? Not sure how to set up this query

I am trying to find products that were bought outside of working hours (9-5). I'm trying to find all of the times that products were bought outside of the 9-5 working hours. However, yellow shirts can be purchased from 7 AM to 5 PM. I'm not sure how to do 2 Where Clauses for that.
There are 100 products. Here is an example:
Product Time_Purchased
Toothbrush 8:00 AM
Yellow Shirt 7:00 AM
Orange Sweatshirt 9:00 AM
Tablet Decoration 10:00 AM
Yellow Shirt 6:00 AM
With this example, the output for Yellow Shirts should not include the 8 AM Time, but it should include the 6 AM.
This is the code I tried running:
PROC SQL
Select * FROM Example
Where (Time_Purchased NOT BETWEEN 32400 AND 61200)
AND Product = 'Yellow Shirt' AND Time_Purchased <25200
quit;
When I run this code, I only get Yellow Shirts purchased before 7:30 and it ignores all of the other products. I'm not sure how to edit the code to show all of the products other than yellow shirts that were purchased outside of 9-5 and the yellow shirts that were purchased outside of 7:30-5 using Where statements.
You can use the OR operator to seperate the 2 conditions in your query. What the OR operator does is return a result if any of the WHERE conditions is true. In your case this would be either 1) when the product is not a yellow shirt and is sold between 9-5 or 2) when the product is a yellow shirt and is sold between 7-5. The query would be similar to the one below:
PROC SQL
SELECT * FROM Example
WHERE Time_Purchased BETWEEN 25200 AND 61200 AND Product = 'Yellow Shirt'
OR Time_Purchased BETWEEN 32400 AND 61200 AND Product != 'Yellow Shirt'
QUIT;
This should work for you.

in sql string partial search

How can I search Product name with minimum query SQL
id product-name
---------------------
1 VFD 1.0HP, 3PHASE VFD2A7MS43ANSAA
2 Cable Flex. PVC 1 core 0.75sq mm Y/G 200m
3 Cable Flex. PVC 1 core 0.75sq mm White 200m
4 Cable Flex. PVC 1 core 0.75sq mm Blue 90m
if I do search with Product name for id 3 - 'flex 1 core cable'.
select *
FROM product
where product-name like '%flex%1%core%cable%'
it does not working properly
if I have search left to right with random word taken---its work properly but if choose word right to left its not fetching data.....
thanks
you can try using different like clauses, so their position won't matter but they'll all be included, example;
select * FROM product where product-name like '%flex%' and product-name like '%1%' and product-name like '%core%' and product-name like '%cable%'

SQL, adding specific transactions for a particular drink on the same order

I am working on seeing which coffee drink sells the most extra condiments (or accessory items like expresso shots, syrup, etc.). Everything is in our MSTransaction, MSOrderLine, or MSProduct tables.
This is the MSorderline table, the extra condiments are ProductID 1444 and 1445. For example, for Purchase ID 421 there was 4 condiments bought for ProductID 1493. So at this point down the list Product 1493 would have 4 sold.
I've been messing around with this and I can't get the results I want...
I understand that this solution wouldn't be correct, but this is as close as I know how to get.

How to select rows which have same value in some column

I have data table "menu" like this
id name type
-----------------------------
10 tea drink
20 krabby patties food
30 coffee drink
40 kelpo food
50 kelp shake drink
I want to select all id of drink, like this
id
---
10
30
50
i'm sorry, can you help me?
Select id from menu where type = 'drink';
This is a basic SQL you can simple search and find it
SELECT ID FROM menu WHERE TYPE='drink';
You can even use IN Operator
Query
SELECT id FROM menu
WHERE type in ('drink');

How to find average in Access?

I am trying out Access for the first time and I am trying to figure out how to really harness the amazing power of Access.
With that, I want to find the average quantity of each item but do not know how to do that. I set up 2 tables. One is the list of items (sand, water, etc.) then set up a relationship to another table that put out the quantities and price.
Below, Query 1 I set up and sorted it (I don't know why it isn't alphabetical even though I sorted ascending, but thats not why I'm here). So could someone help me try and figure out how to average each items amounts like in Query 2? Ultimately, I really just want the query to find the MaxAve and the MinAve and just show those 2 like in Query 3 below.
Query 1 Query 2 Query 3
fldName fldNum fldName fldAve fldName fldAve
Sand 4 Sand 4 Sand 4
Sand 4 Water 3.8 Computer 3.35
Water 3.7 Soda 3.43
Water 4 Computer 3.35
Water 3.7 Phone 3.43
Soda 3.7 Pencil 3.75
Soda 3.3
Soda 3.3
Computer 3.7
Computer 3
Phone 3
Phone 3.3
Phone 4
Pencil 4
Pencil 4
Pencil 3
Like I said I'm very new to Access and I am just trying things out. If you recommend setting up the query a different way Im open to anything really. The more I learn the better.
To get the average for each fieldname, just do this in a query:
SELECT FieldName, Avg(FieldNum) as AvgQty
FROM MyTable
GROUP BY FieldName
ORDER BY FieldName
This will also sort the fieldname column for you.
EDIT:
I think you can do what you asked for in your comment, but you will need a separate query based on the one above. You'll need a UNION query to do it. Something like:
SELECT Top 1 FieldName, AvgQty
FROM Query1
ORDER BY AvgQty ASC
UNION ALL
SELECT Top 1 FieldName, AvgQty
FROM Query1
ORDER BY AvgQty DESC
I'm doing that off the top of my head, so it may not be perfect.
As for formatting the field, do a google on "VBA Format Number" and you should be able to find some examples. I think it might make the above query look something like:
SELECT Top 1 FieldName, Format(AvgQty, "##.#") as AvgQty1
FROM Query1
ORDER BY AvgQty ASC
UNION ALL
SELECT Top 1 FieldName, Format(AvgQty, "##.#") as AvgQty1
FROM Query1
ORDER BY AvgQty DESC