[Solved] Query Problems

Creating tables and queries
Post Reply
fatcat
Posts: 3
Joined: Thu Mar 24, 2016 4:22 am

[Solved] Query Problems

Post by fatcat »

Trying to do a simple query to isolate month using the following;

SELECT DISTINCT "ID" AS "ID", "FIRST NAME" AS "FIRST NAME", "LAST NAME" AS "LAST NAME", "BIRTH DAY" AS "BIRTH DAY", "BIRTH MONTH" AS "BIRTH MONTH" FROM "THSCTABLE" WHERE "BIRTH MONTH" = 'october'

results come up blank for every month, so I started fooling around with it a bit and replaced WHERE "BIRTH MONTH" = 'october' with WHERE "LAST NAME" = 'smith' (a random last name) and it came back with all the smiths in the database. Then tried it with another last name and it came up blank, then with another last name and it hit all those, I kept trying last names that I know are in the database and it is hit and miss as to whether or not I get results. I have also done it with first name and it is also hit and miss.

any ideas for this newby.
Last edited by Hagar Delest on Fri Mar 25, 2016 10:33 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.2 on Windows 7
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Query Problems

Post by UnklDonald418 »

After a quick look at your problem I wonder if the issue is with "BIRTH MONTH" = 'october'
Look at your table and make sure of your spelling and case. In SQL 'october' is not the same as 'October".
Also try SELECT instead of SELECT DISTINCT.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
eremmel
Posts: 1080
Joined: Tue Dec 30, 2008 1:15 am

Re: Query Problems

Post by eremmel »

When you have an issue with capitals in your fields, try: WHERE LOWER("BIRTH MONTH") = 'october'.

Removing the word DISTINCT will not help with your issue, but one should use DISTINCT with care 'cause most of times its use 'solves' buggy queries and that is not what you want.
It's Microsoft marketing that tells you computers are qualified for non-technicians
W11 22H2 (build 22621), LO 7.4.2.3(x64)
fatcat
Posts: 3
Joined: Thu Mar 24, 2016 4:22 am

Re: Query Problems [SOLVED]

Post by fatcat »

Thanks for your help, made me realize the the problem was more basic than expressions. Went back and checked the database table and discovered that all of queries that where not coming back as expected was a result of the data in the cell having spaces behind them. Remove the spaces and the query works. Now I just need an easy way to remove all the spaces in my database.

Thanks again
OpenOffice 4.1.2 on Windows 7
eremmel
Posts: 1080
Joined: Tue Dec 30, 2008 1:15 am

Re: Query Problems [SOLVED]

Post by eremmel »

fatcat wrote: Now I just need an easy way to remove all the spaces in my database.
Thanks again
Run a query

Code: Select all

UPDATE "table1" SET "field1"=RTRIM("field1"), "field2"=RTRIM("field2"), ....
You can run this type of query via (out of my head): menu -> Tools -> SQL...
It's Microsoft marketing that tells you computers are qualified for non-technicians
W11 22H2 (build 22621), LO 7.4.2.3(x64)
fatcat
Posts: 3
Joined: Thu Mar 24, 2016 4:22 am

Re: Query Problems [SOLVED] again

Post by fatcat »

Thanks for that eremmel. Just ran the suggested query and everything is perfect. Cant tell you how much I appreciate the time savings
OpenOffice 4.1.2 on Windows 7
Post Reply