Display matching fields foreignkey with primary key - mysql

I've both table in MySQL
Forwards_signs
+----+-------------+----------+
+ ID + Forward_id + sign_id +
+----+-------------+----------+
+ 4 + 2 + 2 +
+ 5 + 2 + 3 +
+ 4 + 2 + 14 +
+----+-------------+----------+
Signs table
+----+-------------+---------------------------------+
+ ID + Signno + Gejala +
+----+-------------+---------------------------------+
+ 2 + SIG002 + Bulu rontok berlebihan +
+ 3 + SIG003 + Terdapat kebotakan +
+ 14 + SIG004 + Bercak putih seperti ketombe +
+ 8 + SIG008 + Terdapat kerak keropeng +
+ 9 + SIG009 + Warna bulu pucat dan kotor +
+----+-------------+---------------------------------+
I'm used framework CakePHP with relation hasMany() in table method.
the goal that I want to join with matching both table, foreign key will match to Primary Key,
the result that I'm imagine is below
Forwards_signs table Signs table
+----+-----------------+------+----------+---------------------------------+
+ ID + sign_id + ID + Signno + Gejala +
+----+-----------------+------+----------+---------------------------------+
+ 4 + 2 + 2 + SIG002 + Bulu rontok berlebihan +
+ 5 + 3 + 3 + SIG003 + Terdapat kebotakan +
+ 4 + 14 + 14 + SIG014 + Bercak putih seperti ketombe +
+----+-----------------+------+----------+---------------------------------+
thanx for everyone and I hope for help my trouble ..

Related

Can't find what causes "Error in eval(predvars, data, env)" message

I'm running the script below to determine the ten most significant variables via a step regression in my excel sheet. Yes, it is a mess.
patient_data1 = read.csv("PATHWAY_PLACEHOLDER", stringsAsFactors=FALSE, strip.white = TRUE)
nothing <- lm(Gap ~ 1, data = patient_data1)
model <- lm(Gap~HR + RAZscor + PCArati + RMS_sum + KurtSum + razA + razAP + razN + TEigenvec1 + TEigenvec2 + TEigenvec3 + TEigenvec4 + TEigenvec5 + TEigenvec6 + TEigenvec7 + TEigenvec8 + Pax + QRSax + Tax + QRSTax + HR + Pd + PQ + QRS + QT + QTc + TpTe + cTpTe + QEigenvec1 + QEigenvec2 + QEigenvec3 + QEigenvec4 + QEigenvec5 + QEigenvec6 + QEigenvec7 + QEigenvec8 + PEigenvec1 + PEigenvec2 + PEigenvec3 + PEigenvec4 + PEigenvec5 + PEigenvec6 + PEigenvec7 + PEigenvec8 + Patient + hrminsec + BeatNr + RMS40 + fQRSD + LAS + SpatialMean + MeanAngle + QTInterval + SpatialVat + QRSDuration + Vent.Gradient + MaximumAngle + X12LeadArea + X12LeadVoltage + TpTe + QRSRatio + SokolowLyon + CornellVoltage + CornellProduct + SpMeanSD + SPMeanCV + VentGradSD + VentGradCV + SpMeanT + SMTSD + SMTCV + VGFrontal + VGSagittal + VGHor + VMTotalRMS + VMMaxRMS + VMIntegral + ZTotalRMS + ZMaxRMS + ZIntegral + QRSMeanSV + QRSMaxSV + TMeanSV + TMaxSV + PDuration + PNadir + fPDuration + PQInterval + PSpatialMean + PSpMeanSD + PSpMeanCV + PRAngle + PMeanSV + PMaxSV + PFVMIntegral + PVMIntegral + RV6Rmax + RV1SV1 + RV6SV6 + RzDuration + QRSareax + QRSareay + QRSareaz + Tareax + Tareay + Tareaz + VGareax + VGareay + VGareaz + VGFrAzi + VGSagAzi + VGHorAzi + FrQRS10 + FrQRS20 + FrQRS30 + FrQRSMax + FrTMax + SagQRS10 + SagQRS20 + SagQRS30 + SagQRSMax + SagTMax + HorQRS10 + HorQRS20 + HorQRS30 + HorQRSMax + HorTMax + FrUpperR + FrUpperL + FrLowerR + FrLowerL + SagUpperR + SagUpperL + SagLowerR + SagLowerL + HorUpperR + HorUpperL + HorLowerR + HorLowerL + FrontalArea + SagittalArea + HorArea + PA + RL + PL + PALR + Qx + Rx + Sx + Qy + Ry + Sy + Qz + Rz + Sz + X3DQRSmax + FrQRSmax + SagQRSmax + HorQRSmax + X3DTmaxmag + QRSMag18 + QRSElv18 + QRSAzi18 + QRSMag28 + QRSElv28 + QRSAzi28 + QRSMag38 + QRSElv38 + QRSAzi38 + QRSMag48 + QRSElv48 + QRSAzi48 + QRSMag58 + QRSElv58 + QRSAzi58 + QRSMag68 + QRSElv68 + QRSAzi68 + QRSMag78 + QRSElv78 + QRSAzi78 + QRSMag88 + QRSElv88 + QRSAzi88 + EigenQRSa + EigenQRSb + EigenQRSc + EigenQRSarea + PolarVecMag + PolarVecEle + PolarVecAzi + X3DQRS10 + X3DQRS20 + X3DQRS30 + QRSMaxRight + FujitaR + X3DTmean + DEA + e1QRST + e3QRST + Teigenv + RMSTavplan + X3DTmaxElv + X3DTmaxAzi + Tsv1 + Tsv2 + Tsv3 + SAIQRST + Limbsum + JonasMorph + XabsParea + XnetParea + YabsParea + YnetParea + ZabsParea + ZnetParea + PMorph + XabsQRSarea + XnetQRSarea + YabsQRSarea + YnetQRSarea + ZabsQRSarea + ZnetQRSarea + QRSMorph + XabsTarea + XnetTarea + YabsTarea + YnetTarea + ZabsTarea + ZnetTarea + TMorph + STMag18 + STElv18 + STAzi18 + STMag28 + STElv28 + STAzi28 + STMag38 + STElv38 + STAzi38 + STMag48 + STElv48 + STAzi48 + STMag58 + STElv58 + STAzi58 + STMag68 + STElv68 + STAzi68 + STMag78 + STElv78 + STAzi78 + STMag88 + STElv88 + STAzi88 + PatientID + DocumentName + Date + Time + Pax + QRSax + Tax + HR + PQ + Pd + QRS + QT + QTc + pamp_1 + ppamp_1 + qdur_1 + qamp_1 + rdur_1 + ramp_1 + sdur_1 + samp_1 + rpdur_1 + rpamp_1 + spdur_1 + spamp_1 + ston_1 + stmid_1 + st80_1 + stslope_1 + tamp_1 + tpamp_1 + pamp_2 + ppamp_2 + qdur_2 + qamp_2 + rdur_2 + ramp_2 + sdur_2 + samp_2 + rpdur_2 + rpamp_2 + spdur_2 + spamp_2 + ston_2 + stmid_2 + st80_2 + stslope_2 + tamp_2 + tpamp_2 + pamp_3 + ppamp_3 + qdur_3 + qamp_3 + rdur_3 + ramp_3 + sdur_3 + samp_3 + rpdur_3 + rpamp_3 + spdur_3 + spamp_3 + ston_3 + stmid_3 + st80_3 + stslope_3 + tamp_3 + tpamp_3 + pamp_4 + ppamp_4 + qdur_4 + qamp_4 + rdur_4 + ramp_4 + sdur_4 + samp_4 + rpdur_4 + rpamp_4 + spdur_4 + spamp_4 + ston_4 + stmid_4 + st80_4 + stslope_4 + tamp_4 + tpamp_4 + pamp_5 + ppamp_5 + qdur_5 + qamp_5 + rdur_5 + ramp_5 + sdur_5 + samp_5 + rpdur_5 + rpamp_5 + spdur_5 + spamp_5 + ston_5 + stmid_5 + st80_5 + stslope_5 + tamp_5 + tpamp_5 + pamp_6 + ppamp_6 + qdur_6 + qamp_6 + rdur_6 + ramp_6 + sdur_6 + samp_6 + rpdur_6 + rpamp_6 + spdur_6 + spamp_6 + ston_6 + stmid_6 + st80_6 + stslope_6 + tamp_6 + tpamp_6 + pamp_7 + ppamp_7 + qdur_7 + qamp_7 + rdur_7 + ramp_7 + sdur_7 + samp_7 + rpdur_7 + rpamp_7 + spdur_7 + spamp_7 + ston_7 + stmid_7 + st80_7 + stslope_7 + tamp_7 + tpamp_7 + pamp_8 + ppamp_8 + qdur_8 + qamp_8 + rdur_8 + ramp_8 + sdur_8 + samp_8 + rpdur_8 + rpamp_8 + spdur_8 + spamp_8 + ston_8 + stmid_8 + st80_8 + stslope_8 + tamp_8 + tpamp_8 + pamp_9 + ppamp_9 + qdur_9 + qamp_9 + rdur_9 + ramp_9 + sdur_9 + samp_9 + rpdur_9 + rpamp_9 + spdur_9 + spamp_9 + ston_9 + stmid_9 + st80_9 + stslope_9 + tamp_9 + tpamp_9 + pamp_10 + ppamp_10 + qdur_10 + qamp_10 + rdur_10 + ramp_10 + sdur_10 + samp_10 + rpdur_10 + rpamp_10 + spdur_10 + spamp_10 + ston_10 + stmid_10 + st80_10 + stslope_10 + tamp_10 + tpamp_10 + pamp_11 + ppamp_11 + qdur_11 + qamp_11 + rdur_11 + ramp_11 + sdur_11 + samp_11 + rpdur_11 + rpamp_11 + spdur_11 + spamp_11 + ston_11 + stmid_11 + st80_11 + stslope_11 + tamp_11 + tpamp_11 + pamp_12 + ppamp_12 + qdur_12 + qamp_12 + rdur_12 + ramp_12 + sdur_12 + samp_12 + rpdur_12 + rpamp_12 + spdur_12 + spamp_12 + ston_12 + stmid_12 + st80_12 + stslope_12 + tamp_12 + tpamp_12 + DiagnosticStatements + Gender + Outcome + Age + Ln.Cornell.Product + QRSAzi.5.8.minus.QRS.Azi.4.8 + QRS.Azi.6.8.minus.QRS.Azi5.8 + QRSMinAziSineRAD + LnNEigen5
, patient_data1)
stepwiseregression <- step(object = nothing, scope = list(lower = formula(nothing), upper = formula(model), direction = "forward"))
summary(stepwiseregression)
The problem is that when I run the script, I get the error message "Error in eval(predvars, data, env) : object 'r' not found". This despite the fact that I don't think that I'm making a prediction (correct me if I'm wrong) and I can't find 'r' as an object. Can anyone see what I'm doing wrong and suggest a solution?
I've tried searching for 'r' in my code, but it doesn't come up in any other context than as a letter in a longer name of a column.

mysql copy database rows from database 1 multiple times to new database 2, looping through a value of database 3

I want to copy values from on table to another using mysql, while looping through a third table to set a specific value in the second.
Table 1 is called countries, with structure and data:
countries
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ countries_id + countries_name + countries_iso_code_2 + countries_iso_code_3 +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 + Belgium + BE + BEL +
+ 2 + Netherlands + NL + NLD +
+ 3 + Germany + DE + DEU +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The rows countries_id and countries_name need to be copied to table countries_name. For each language_id from table languages.
Table 2
countries_name
+++++++++++++++++++++++++++++++++++++++++++++++
+ countries_id + language_id + countries_name +
+++++++++++++++++++++++++++++++++++++++++++++++
+ 1 + 1 + Belgium +
+ 2 + 1 + Netherlands +
+ 3 + 1 + Germany +
+ 1 + 3 + Belgium +
+ 2 + 3 + Netherlands +
+ 3 + 3 + Germany +
+ 1 + 4 + Belgium +
+ 2 + 4 + Netherlands +
+ 3 + 4 + Germany +
+++++++++++++++++++++++++++++++++++++++++++++++
table 3
languages
+++++++++++++++++++++++++++++++++
+ languages_id + name + code +
+++++++++++++++++++++++++++++++++
+ 1 + English + en +
+ 3 + Dutch + nl +
+ 4 + German + de +
+++++++++++++++++++++++++++++++++
I know how to do this for a single pass, but not for multiple.
CREATE TABLE countries_name (
countries_id int(11) NOT NULL,
language_id int(11) NOT NULL DEFAULT 1,
countries_name varchar(64) NOT NULL,
UNIQUE countries (countries_id, language_id),
KEY idx_countries_name_zen (countries_name)
) ENGINE=MyISAM;
INSERT INTO countries_name (countries_id, countries_name)
SELECT c.countries_id, c.countries_name
FROM countries c;
http://sqlfiddle.com/#!9/bd3c7/1
If I got your goal correctly:
INSERT INTO countries_name (countries_id, language_id, countries_name)
SELECT
c.countries_id,
l.languages_id,
c.countries_name
FROM countries c
LEFT JOIN languages l
ON 1;

Replace just start of string in sql

I have 3 columns in my table:
+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name + Cell +
++++++++++++++++++++++++
+ 1 + FB + /moon/ta +
+ 2 + GO + /ta/ta +
+ 3 + MO + /ta/mon +
+ 4 + SS + /ta +
+ 4 + SS + /ta/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++
I want to replace all "/ta" with "/rr" in cell that start of string, like:
+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name + Cell +
++++++++++++++++++++++++
+ 1 + FB + /moon/ta +
+ 2 + GO + /rr/ta +
+ 3 + MO + /rr/mon +
+ 4 + SS + /rr +
+ 4 + SS + /rr/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++
How can I do this in SQL?
I think this does what you want:
update table t
set cell = concat('/rr', substr(cell, 4))
where cell like '/ta%';

MySQL UPDATE with subquery with group by

I have the following tables on MySQL:
**Elements**
+------+------------------+------------------+
+ Id + Name + referenced +
+------+------------------+------------------+
+ 1 + element1 + NULL +
+ 2 + element2 + NULL +
+ 3 + element3 + NULL +
+ 4 + element4 + NULL +
+ 5 + element5 + NULL +
+ 6 + element6 + NULL +
+------+------------------+------------------+
**References**
+------+------------------+------------------+
+ Id + Name + type +
+------+------------------+------------------+
+ 1 + element1 + 1 +
+ 2 + element1 + 2 +
+ 3 + element3 + 1 +
+ 4 + element3 + 2 +
+ 5 + element3 + 3 +
+ 6 + element4 + 1 +
+ 7 + element5 + 2 +
+ 8 + element5 + 3 +
+------+------------------+------------------+
The "referenced" column on "Elements" table should have 0 for no reference of its name on "References" table and 1 for at least one reference of its name on "References" table.
This result could be selected with the following query:
SELECT Elements.Id, Elements.Name, (References.Id is not null) as referenced FROM
Elements
LEFT JOIN
References ON Elements.Name = References.Name
GROUP BY Elements.Name ORDER by Elements.Id;
+------+------------------+------------------+
+ Id + Name + referenced +
+------+------------------+------------------+
+ 1 + element1 + 1 +
+ 2 + element2 + 0 +
+ 3 + element3 + 1 +
+ 4 + element4 + 1 +
+ 5 + element5 + 1 +
+ 6 + element6 + 0 +
+------+------------------+------------------+
But I could't find a way to update the "Elements" table with this result.
Any ideas?
UPDATE Elements e
LEFT JOIN References r ON e.OneName = r.OtherName
SET e.referenced = r.OtherName IS NOT NULL;

Boolean Simplification

I have a boolean simplification problem that's already been solved.. but I'm having a hard time understanding one basic thing about it.. the order in which it was solved.
The problem is simplifying this equation:
Y = ¬A¬B¬C + ¬AB¬C + A¬B¬C + A¬BC + ABC
The solution is:
Y = ¬A¬B¬C + ¬AB¬C + A¬B¬C + A¬BC + ABC
= ¬A¬B¬C + ¬AB¬C + A¬B¬C + A¬BC + A¬BC + ABC (idempotency for A¬BC)
= ¬A¬C(¬B + B) + A¬B(¬C + C) + AC(¬B + B)
= ¬A¬C + A¬B + AC
The way I solved it is:
Y = ¬A¬B¬C + ¬AB¬C + A¬B¬C + A¬BC + ABC
= ¬A¬B¬C + ¬AB¬C + ¬A¬B¬C + A¬B¬C + A¬BC + ABC (idempotency for ¬A¬B¬C)
= ¬A¬C(¬B + B) + ¬B¬C(¬A + A) + AC(¬B +B)
= ¬A¬C + ¬B¬C + AC
So how do I know which term to use the law of idempotency on? Thanks.
¬A¬B¬C + ¬AB¬C + A¬B¬C + A¬BC + ABC
¬A¬C(¬B + B) + A(¬B¬C + ¬BC + BC)
¬A¬C + A(¬B¬C + ¬BC + BC) <- see truth table below for the simplification of this
¬A¬C + A(¬B + C)
¬A¬C + A¬B + AC
truth table:
B C
0 0 = 1 + 0 + 0 = 1
0 1 = 0 + 1 + 0 = 1
1 0 = 0 + 0 + 0 = 0
1 1 = 0 + 0 + 1 = 1
which is ¬B + C