MS Access Query Goes Blank If No Rows In Another Query - ms-access

This has been driving me nuts for awhile now.
So I have Query_A and Query_B that I need to combine into one query called Query_C.
This works perfectly fine. But if Query_B returns no results or zero rows because of a filter, then Query_C goes blank or to zero rows as well.
Is there any way to have Query_C still display the results of Query_A even if Query_B has no rows?
I have been doing null to zero in the past which works fine but its a pain to do it for each column and alot of times I have to make another query just for doing the null to zero part. And on top of it then I have formatting problems and have to format each column as well. It always ends up being so many queries and so much extra work it just seems dumb.
Is there a better way of doing this?

Consider a subquery UNION or UNION ALL
SELECT *
FROM
(Query_A UNION Query_B) AS Query_C

Adding a left join solved the problem. Made a dummy feild in each table and joined them with that for the test.

Related

How do I sum multiple rows and show all columns?

Picture of the Query
SELECT *, SUM(match_attendance) FROM new_dashboard
Group BY worldcup_year;
I used this but don't know if it is correct? Is there like a proper way to do it? Via subquery or what not? Cause Im not sure showing if this is how people do it. I notice alot list all the column they wish to select then use the sum function but if you have like 20 columns that don't make sense.

Why would MySQL return NULL yet there is a value in the field?

I am running a join on 3 large tables (over a hundred thousand rows each). The query returns 4 rows as expected, but one of the rows has a "NULL" value, yet in the table is a value I expect to see. I am sure the value is in the db because I can see it in the table, but for some reason, MySQL is returning everything except that particular value. I am not getting any errors. The query runs exactly as expected, except for this null value. See the screenshot below:
My Question is why would this happen? Has anybody experienced this? Could it be a bug in phpmyadmin? This query is supposed to be a report of some transactions, so you can imagine how funny the report is looking with a blank field that cannot be explained!
have you tried doing it with the inner join (clasic one) , when you do a left join it brings all rows from the left table and those who did not match have null values.
here they explain it better and you can see examples
https://www.w3schools.com/sql/sql_join.asp

Access Union drops combo boxes Displays -1 or 0 in datasheet view

I had to share this as it drove me nuts for ages.
Issue I had
I required to get the same data displayed using many iif statements which looked at specific columns. The next thing the client wanted was to have different results of if statements depending on another column not associated. Meaning I needed to run a multiple query hence I had to use a UNION statement to join the queries.
The issue was when running the querys within a UNION removed the check box and showed the raw data in the database of -1 or 0. This is a qwerk of unions.
Running the queries independently returned the data with the check box.
Solution
create your union with the multiple queries.
Then create another query that queries the union and on the columns that require the combo box. Select properties, Select lookup and change display control to Check Box.
Hope this helps somebody. Drove me nuts for ages
Solution create your union with the multiple queries. Then create another query that queries the union and on the columns that require the combo box. Select properties, Select lookup and change display control to Check Box.
Hope this helps somebody. Drove me nuts for ages

MySQL query SELECT as item

I was fiddling with some mySQL I had written a while ago and I was wondering how to make the queries more efficient. After doing some research I came across a website that said
SELECT (SELECT Value FROM table WHERE (variable1 == "answer" AND variable2 = "answer2")) AS variable;
could be used, in theory, to return either NULL if nothing was found or the value if the criteria were met.
Having tried this, I could not get it to work. Could someone tell me if either:
1. I'm doing this stupidly and there is a more efficient system for doing this (that is not count)
2. It works, but what I'm doing wrong with it
If you want to get a a single value if it exists, otherwise NULL (instead of an empty result set), this approach is as efficient as it will get. The time it takes will be the same as the time it takes to run the inner query alone.
The only problem is that the if inner query returns more than one row you will get an error. You can fix that by adding LIMIT 1 or making sure it never returns more than one row.

How could SUM(column) give incorrect results in MySQL?

I have the following simple MySQL query, called from PHP:
SELECT foo_id, SUM(number_of_guests)
FROM guests
WHERE foo_id = $foo_id
GROUP BY foo_id
This works fine, except for one $foo_id, which returns about 2.5 times greater than the sum of the number_of_guests field.
What could cause this behavior for only a certain value of $foo_id?
Is there a better way to do this?
Your query should work. The error is most likely in the other method you are using to verify the result.
Is there a better way to do this?
Yes. Since you are only fetching one group there's no need for your GROUP BY clause:
SELECT SUM(number_of_guests)
FROM guests
WHERE foo_id = $foo_id
The problem is that there was one row with a large value for number_of_guests. I didn't see in in browsing the data because there are a few hundred rows. It didn't show up when I copied and pasted from HTML page into Excel because that row was missing most of the other columns, and the HTML page has all the columns.
Thanks for all your help!