mysql - SQL Checking if a user relationship exist -


i have user relationship table set looks this.

user_relationship

  • relationship_id
  • requesting_user_id
  • requested_user_id
  • relationship_type
  • relationship_status

now want check relationship see if exist between 2 users lets example ids 1 & 2. a:

select *    user_relationship   (requesting_user_id='1' ,  requested_user_id='2')      || (requesting_user_id='2' ,  requested_user_id='1') 

but wondering if better faster way this?

ors notoriously bad performers. try union instead:

select a.*    user_relationship  a.requesting_user_id = '1'     , a.requested_user_id = '2' union select b.*    user_relationship b  b.requesting_user_id = '2'     , b.requested_user_id = '1' 

union remove duplicates; union all not (and faster it).

if there columns coming don't use -- shouldn't in query.

indexing should on:

  • requesting_user_id
  • requested_user_id

...either separately or single composite index you'll have test know works best.


Comments

Popular posts from this blog

sql server - python to mssql encoding problem -

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -