LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2020, 02:40 PM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
[sql] matching records from 2 tables with multiple fields


hi, i am wanting to pull records from a query like so:
Code:
table-1:
claim-prefix claim-id claim-segment-number member-id
s            al3r     0                    chun-li
a            h3l0     1                    ryu
...

table-2:
claim   date
sal3r00 2020-02-18-12:00:00
msux005 2020-02-18-13:00:00
...
and i wanna':
Code:
select claim, member-id, date
from table-1, table-2
where claim = 'sal3r00'
and claim-prefix+claim-id+char(claim-segment-number) = claim
order by date desc
with ur;
--------------------
sal3r00 chun-li 2020-02-18-12:00:00
but i cant punch up the correct syntax ?

in db2-sql, seems like concat() only allows for two arguments.

Last edited by schneidz; 02-18-2020 at 03:21 PM.
 
Old 02-18-2020, 03:36 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this worx:
Code:
AND claim-prefix CONCAT claim-id CONCAT LPAD(claim-segment-number,2,'0') = claim
 
Old 02-19-2020, 07:38 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
I don't know anything about DB2, but with other database systems doing that type of comparison prevents indexes being used, so if this system is expected to scale you might want to just create a claim column in table-1 instead, and perform the concatenation on insert.

 
Old 02-19-2020, 09:24 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by boughtonp View Post
I don't know anything about DB2, but with other database systems doing that type of comparison prevents indexes being used, so if this system is expected to scale you might want to just create a claim column in table-1 instead, and perform the concatenation on insert.

bon idée:
Quote:
Originally Posted by schneidz View Post
i agree, the mainframe dataset is pulled from db2, vsam, i.d.m.s., websphere mqueues and other datasets.

to get an additional column added, business solutions delivery would have to create a service request; then, app-dev would need to design it; and, enterprise release management would need to approve the budget.
 
Old 02-19-2020, 11:38 AM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Build a temporary table which includes the claim column, then JOIN on that table to get the result.

Not certain of db2 syntax but I know it supports temporary tables, something like this in pseudo-sql:

Code:
CREATE TEMPORARY TABLE tmpclaim(
    SELECT CONCAT(claim-prefix, claim-id, claim-segment-number) AS claim, member_id FROM table-1
);

CREATE INDEX claimindx(claim) on tmpclaim;

SELECT claim, member_id, date 
FROM tmpclaim JOIN table-2 USING(claim) 
WHERE claim='sal3r00';
But if the database uses those columns as a compound key in one table, then uses their concatenation as a key into another table, the data model is in need of a little normalization (which the temporary table provides, more or less, temporarily).

Last edited by astrogeek; 02-19-2020 at 12:01 PM.
 
1 members found this post helpful.
Old 02-19-2020, 05:13 PM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by schneidz View Post
to get an additional column added, business solutions delivery would have to create a service request; then, app-dev would need to design it; and, enterprise release management would need to approve the budget.
Or you just get friendly with a DBA.

 
Old 02-20-2020, 08:35 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by boughtonp View Post
Or you just get friendly with a DBA.

i once had to request extra space from storage management and their quote was cost per gb is $2.32 per month.
i factored this into $2,320/month -> $27,840/year -> $278,400/decade. i pointed out that a 1 tb sd-card on newegg costs like $45.

Last edited by schneidz; 02-20-2020 at 08:36 AM.
 
Old 02-20-2020, 08:35 AM   #8
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
DB2 does have some string functions. If you know the length of each component of the claim string you could separate it into its constituent parts using SUBSTR() and select on the fields.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk with pipe delimited file (specific column matching and multiple pattern matching) lolmon Programming 4 08-31-2011 12:17 PM
[SOLVED] Matching two tables of non-matching sizes astroumut Programming 3 03-03-2011 07:05 AM
[SOLVED] MX Records / A Records / CNAME Records - Advice Please fusion1275 Linux - Newbie 15 01-18-2011 04:06 AM
How to compare records in two tables in seperate My Sql database using perl script chandanperl Programming 1 08-22-2008 09:33 AM
How to compare records in two tables in seperate My Sql database using shell script sumitarun Programming 5 04-14-2005 09:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration