suv
suv

Reputation: 1543

How do I achieve the following using JOIN statement in mysql?

I have

TABLE 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

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.

So far my SQL statement is:

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?

How do I modify the statement so that it returns me r_arn and r_deviceType only corresponding to a specific r_profileid?

Upvotes: 1

Views: 60

Answers (4)

Amran Hossain
Amran Hossain

Reputation: 152

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';

Upvotes: 2

Prasath Bala
Prasath Bala

Reputation: 728

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;

Upvotes: -1

ngrashia
ngrashia

Reputation: 9894

Use a WHERE clause.

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

WHERE R_PROFILEID = 'SOME_VALUE';

If you want for a range of profileIds , then use

WHERE R_PROFILE_ID IN ('VALUE1','VALUE2','VALUE3');

Upvotes: 2

Rahul Tripathi
Rahul Tripathi

Reputation: 172408

You need to put a where condition in your MYSql query.

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";

Upvotes: 1

Related Questions