Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

Requesting help with creating an SQL query to select similar records

This is a little hard to explain but I will do my best.  I need to write/update the example query below  so that it will return the records requested, but also return records based on what was returned. In my example below, two records are returned with "carnumber 55". I want to show those 2 records, but also any other records with the same "carname". In my example below, 3 additional records are displayed because they have the same car name as those returned from the original query. Can someone assist?

Select id, carnumber, carname
from tblOne 
where carnumber = 55

What I want returned from the new query

id   |   carnumber   |   carname
1    |      55       |   bobs car
5    |      55       |   johns car
7    |      88       |   bobs car
8    |      77       |   bobs car
21   |      97       |   johns car

Open in new window

Avatar of Muhammad Burhan
Muhammad Burhan
Flag of Pakistan image

try this
select * from table01
where carname = 'bobs car'
order by carnumber
Avatar of earwig75
earwig75

ASKER

@muhammad, I will not have the carname in my query, I will only have the carnumber, that's why I need to use the results from the initial query to get the carname.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!