[SOLVED] [sql] matching records from 2 tables with multiple fields
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[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.
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.
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
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.
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).
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.