[英]How do I achieve the following using JOIN statement in mysql?
I have 我有
TABLE 1: r_profile_token
表1:
r_profile_token
Columns: 列:
r_sequence int(45) AI PK
r_profileid varchar(45)
r_token varchar(300)
r_deviceType int(1)
r_date date
r_time time
and 和
TABLE 2: r_token_arn
表2:
r_token_arn
Columns: 列:
r_token varchar(300) PK
r_arn varchar(300)
I need a result of the form - 我需要表格的结果-
r_profileid
r_arn
r_deviceType
where I can specify the r_profileid
. 我可以在其中指定
r_profileid
。
So far my SQL statement is: 到目前为止,我的SQL语句是:
SELECT
b.r_arn,
a.r_deviceType
FROM
coffee2.r_profile_token a INNER JOIN
coffee2.r_token_arn b
ON a.r_token=b.r_token;
Which returns r_arn
and r_deviceType
but for all r_profileid? 哪一个返回
r_arn
和r_deviceType
但返回所有 r_profileid?
How do I modify the statement so that it returns me r_arn
and r_deviceType
only corresponding to a specific r_profileid
? 如何修改语句,以便它返回我
r_arn
和r_deviceType
只对应于特定r_profileid
?
Use a WHERE
clause. 使用
WHERE
子句。
SELECT B.R_ARN, A.R_DEVICETYPE
FROM COFFEE2.R_PROFILE_TOKEN A
INNER JOIN
COFFEE2.R_TOKEN_ARN B
ON A.R_TOKEN=B.R_TOKEN
WHERE R_PROFILEID = 'SOME_VALUE';
If you want for a single profileid, then use 如果您想要一个profileid,请使用
WHERE R_PROFILEID = 'SOME_VALUE';
If you want for a range of profileIds , then use 如果您需要一定范围的profileIds,请使用
WHERE R_PROFILE_ID IN ('VALUE1','VALUE2','VALUE3');
You can try this Query against your requirements. 您可以根据自己的要求尝试此查询。
SELECT
b.r_arn,
a.r_deviceType ,
a.r_profileid
FROM
r_profile_token a
INNER JOIN
r_token_arn b
ON
a.r_token=b.r_token
where r_profileid='profile name';
You need to put a where
condition in your MYSql query. 您需要在MYSql查询中放置一个
where
条件。
select b.r_arn, a.r_deviceType from coffee2.r_profile_token a
INNER JOIN coffee2.r_token_arn b on a.r_token=b.r_token
where r_profileid = "Specific value";
select b.r_arn, a.r_deviceType, a.r_profileid from r_profile_token a
INNER JOIN r_token_arn b on
a.r_token=b.r_token;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.