sql - Writing a query for multiple fields using IN -


select a.first_name,b.empid,c.phn name a,emp b,phone c b.emptype = 'new' , a.first_name,b.last_name,c.phn = (select a.first_name,b.last_name,c.phn name a,emp b,phone c b.emptype = 'old') 

basically, want search new customers have same details (first name, last name , phone) old customers. old customer can converted new customer details retained. hence, thing changes emptype.

eg. (john mcenroe 47589876 old) when converted becomes (john mcenroe 475898876 new) [first_name,last_name,phone,emptype]

dude, here's query uses exists. main difference between exists , in exists queries using index in goes lot of or toghether.

select a.first_name     ,b.empid     ,c.phn name     ,emp b     ,phone c b.emptype = 'new'     , exists (select top 1 1                     name x                     ,emp y                     ,phone z                                     x.first_name = a.first_name                 , y.last_name = b.last_name                 , z.phn = c.phn                 , y.emptype = 'old'             ) 

now, looking @ query, have 3 tables, not joined toghether (name, emp, phone) have real mess data come output. be, formula:

(1st table rows qty) multiplied (2nd table rows qty) multiplied (3rd table rows qty)

means if each table have 100 rows, you'll this:

100 x 100 x 100 = 1000000 rows in result (awful right?)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -