Hello,
A novice question on SQL in Base:
I would like to compare two strings in the same row and report the result. I think this is equivalent to "StrComp", but I am unable to get that to work.
For example,
Table
A B C
1 Bob Ivan
2 Jane Bob
3 Jose Jose
I'd like a report that somehow shows A3 has matching data in fields B and C, by flagging the row somehow. Something like?
SELECT A, StrComp("B","C")
FOR Table
I've been trying things and looking up ideas for awhile and finally admit I am stumped. I can make a report of all rows that have the matching data, but want a report with all rows with and without matches.
Thank you for your time,
John
[Solved] SQL Query Comparing Strings
-
- Posts: 3
- Joined: Thu May 07, 2020 1:36 am
[Solved] SQL Query Comparing Strings
Last edited by JohnNorris on Fri May 08, 2020 6:33 am, edited 2 times in total.
Open Office 4.1.7 on Windows 10
Re: SQL Query Comparing Strings
Will this meet your needs?
Code: Select all
SELECT "A", "B", "C"
FROM "Table_2"
WHERE "B" = "C"
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: SQL Query Comparing Strings
I think OP wants an extra flag to indicate whether the row has a duplicate or not. My SQL is a bit rusty, but something along the lines of
If Hsql doesn't support IF perhaps CASE might work.
Code: Select all
SELECT "A", IF ("B"="C",'Duplicate','Unique') FROM table ....
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Re: SQL Query Comparing Strings
I think that would berobleyd wrote:I think OP wants an extra flag to indicate whether the row has a duplicate or not. My SQL is a bit rusty, but something along the lines ofIf Hsql doesn't support IF perhaps CASE might work.Code: Select all
SELECT "A", IF ("B"="C",'Duplicate','Unique') FROM table ....
Code: Select all
SELECT "A", CASE WHEN "B" = "C" THEN 'Duplicate' ELSE 'Unique' END AS "Flag"
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
-
- Posts: 3
- Joined: Thu May 07, 2020 1:36 am
Re: SQL Query Comparing Strings
Thank you for the quick reply. That confirmed that I can compare text strings with the equal sign. I wasn't sure about that. I was thinking I would have to use "like" or something. Very helpful.FJCC wrote:Will this meet your needs?Code: Select all
SELECT "A", "B", "C" FROM "Table_2" WHERE "B" = "C"
Open Office 4.1.7 on Windows 10
-
- Posts: 3
- Joined: Thu May 07, 2020 1:36 am
Re: SQL Query Comparing Strings
I think that would be
[/quote]
Thanks to you both. The above is pretty much what I wanted. I've confirmed that it works with my simple table.
The "CASE" function is not something I've explored before. An If/Then function is very powerful; so many thanks from me.
John
Code: Select all
SELECT "A", CASE WHEN "B" = "C" THEN 'Duplicate' ELSE 'Unique' END AS "Flag"
Thanks to you both. The above is pretty much what I wanted. I've confirmed that it works with my simple table.
The "CASE" function is not something I've explored before. An If/Then function is very powerful; so many thanks from me.
John
Open Office 4.1.7 on Windows 10
Re: [SOLVED] SQL Query Comparing Strings
I assume you are using the embedded hsql V 1.8; if so you might find the hsql documentation for 1.8 a useful resource, particularly Section 9.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers