Reputation: 1147
I have table called progress which stores different type of progress for both client and member;
I have a MYSQL Query, which is suppose to get progress data both from the client to member and member to client. Currently I have a queries in the following way;
SELECT *
FROM progress
WHERE (client = 'XXXX' AND member = 'YYYY')
OR (client = 'YYYY' AND member = 'XXXX')
it gets me the result I want, but how can I improve this query in terms of the way it is written.
Please help, any help is much appreciated.
Thank you in advance
Upvotes: 0
Views: 38
Reputation: 23371
As Barmar said in the comments It can't get much simpler
but you have some options as per your question of WRITING this query:
You can use a UNION
select * from progress where (client = 'xxxx' and member = 'yyyy')
union all
select * from progress where (client = 'yyyy' and member = 'xxxx')
You can use IN
statements
select * from progress
where (client) in ('XXXX','YYYY')
and (member) in ('YYYY','XXXX');
And you can use your own solution.
Edit
Forgot to add the fiddle i did: http://sqlfiddle.com/#!2/74e6ec/7
Upvotes: 2
Reputation: 108
Try using a Union.
SELECT * FROM progress WHERE (client = 'XXXX' AND member = 'YYYY')
UNION ALL
SELECT * FROM progress WHERE (client = 'YYYY' AND member = 'XXXX')
Upvotes: 0