Reputation: 13
I'm new in sql and I need help for this case using subquery.
I this case I need to grab all customerId under Amanda and UAmanda.But now I only have this customerId 100456.
How to I use this customerId 100456 combain subquery to get all data under Amanda and UAmanda.
Below is the table
Customer_Id | Login_Name |
---|---|
100456 | Amanda |
101287 | UAmanda |
102458 | Oliver |
103658 | Louis |
This is my subquery
select customer_id,login_name
from
(select tc.customer_id, tc.login_name from t_customers tc where tc.login_name = login_name)
where t_customers where customer_id = 100456;
but it only return me the Amanda with 100456 the others UAmanda did not return.
Can anyone help me on this issue?
This is the expected result I want
Customer_Id | Login_Name |
---|---|
100456 | Amanda |
101287 | UAmanda |
Upvotes: 0
Views: 33
Reputation: 32599
Given you say the only data you have is the customer_Id
I believe you need the following:
select *
from customers
where login_name like (
select Concat('%',Login_Name,'%')
from customers
where Customer_Id=100456
)
Upvotes: 0
Reputation: 1821
If you want to grab all customerId under Amanda and UAmanda then I think there is no need of sub query. You can get the result using below query:
select customer_id, login_name
from t_customers
where login_name in ('Amanda', 'UAmanda');
Upvotes: 0
Reputation: 1321
SELECT customer_id, login_name FROM t_customers WHERE login_name LIKE '%Amanda';
Upvotes: 1