[Solved] Query is not showing all lines from table

Creating tables and queries
Post Reply
matroSK
Posts: 19
Joined: Thu Jul 23, 2015 10:37 am

[Solved] Query is not showing all lines from table

Post by matroSK »

Hi guys.
I´m new to Base (like months or two), this is my first time posting here and English is not my primary language, so I hope you will be patient with me.

I´m doing database, where I'm putting together information about buildings (e.g. if it's completed, how much is done (%) etc.) and workers (e.g. how much they should get paid, time spend on building etc.).
Every building have special number so I know where which worker were and the number is in every table, so I can connect it through it.

My problem is that I have one table with main info about buildings and than another table with info about workers and how much time do they spend there. Every day is in different line.
Than I have query where have these two tables and I count the time totally spent (by workers) in concrete one, but not all buildings are actually being under “reconstruction“, so not all are mentioned there.

Than the result is that not all buildings are being showed in that query.
Is there any possibility it could show me all buildings also those one without the working time on it?

Example: Building number 6 is new and workers haven´t been there yet, but I still want to see it in that query (query continue to form..) eventhough there is no time spend on it.


Hope you understand what my trouble is. If not here is picture

Image

Table 1. is Buildings table and the columns are – number of bulding (special number that I´ve already mentioned), name of it and the others are not important

Table 2. is Workers table and the columns are – number of worker (everyone have special number, names are in different table), date, hours spent on building, not important, not important and the last one is number of building.

Those two underline with red are connected in query.

And in query the first is name of building, not important, hours spent there (counted together) and not important.

If you have any questions or you don't understand anything, please ask me.
Thanks.
Matro

And sorry I couldn´t find better name for this topic.
Last edited by matroSK on Fri Jul 24, 2015 9:15 am, edited 1 time in total.
Apache OpenOffice 4.1.1
Windows 7 Ultimate
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Query is not showing all lines from table

Post by MTP »

I'm not sure how to do this in design view.

In SQL view, if I understand you correctly, you are currently doing an INNER JOIN that only shows matching rows. What you want is a LEFT JOIN that shows everything in the first table (the "left table" in languages that read left to right), regardless of whether this is a match in the second table. So like this:

Code: Select all

SELECT "Zmluvy"."C_stavby", 
   "Zmluvy"."Popis_objektu", 
   SUM("Dochadzka"."P_hodin") AS "P_hodinSUM"
      FROM "Zmluvy"
      LEFT JOIN "Dochadzka" ON "Zmluvy"."C_stavby" = "Dochadzka"."C_stavby"
   GROUP BY "Zmluvy"."C_stavby", "Zmluvy"."Popis_objektu"
Did I understand your question? Does that help?
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
matroSK
Posts: 19
Joined: Thu Jul 23, 2015 10:37 am

Re: Query is not showing all lines from table

Post by matroSK »

Ah sorry I didn´t realise I should have post also SQL view here. But from what I see now it's working great and this is exactly what I needed, so I guess I can mark this thread as solved.
Thanks for quick and very usefull answer.
Apache OpenOffice 4.1.1
Windows 7 Ultimate
Post Reply