Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi,

I have table
SQL
CREATE TABLE supportContacts 
	(
     id int auto_increment primary key, 
     type varchar(20), 
     details varchar(30),
      code_id int
    );

INSERT INTO supportContacts
(type, details,code_id)
VALUES
('Email0', '0admin@sqlfiddle.com',1033),
('Email1', '1admin@sqlfiddle.com',1031),
('Email2', '2admin@sqlfiddle.com',1033),
('Email3', '3admin@sqlfiddle.com',1031),
('Email5', '5admin@sqlfiddle.com',1032),
('Email6', '6admin@sqlfiddle.com',1032),
('Twitter4', '4@sqlfiddle',1033);


when i ran this query

SQL
Select type from supportContacts where code_id=1033
union 
(
  Select type from supportContacts where code_id
  not in (Select type from supportContacts where code_id=1033)
)

output is
TYPE
Email0
Email2
Twitter4
Email1
Email3
Email5
Email6

I want to replace this query with join's how can i do that.

Thanks
Posted
Updated 3-Dec-13 7:44am
v2
Comments
ZurdoDev 3-Dec-13 13:51pm    
It's the same table. Why would you want to join?
Member 8128040 3-Dec-13 14:06pm    
actaully ryan this is the sample its a subquery which is used inside a big query which i have to improve for performance.
ZurdoDev 3-Dec-13 14:08pm    
OK. But explain in English what you are trying to do and then we can help.
RaisKazi 3-Dec-13 13:52pm    
I doubt your sub-query is working.
Member 8128040 3-Dec-13 14:09pm    
may be there's some problem at ur sql engine...
its a simple wat's wrong in this...

1 solution

i got d answer without any join
finally what i want data which comes as per d order of "query" before union clause
so i just use order by and when

Select type from supportContacts
order by
case when code_id=1033 then 1 end desc

please suggest is i m wrong....
 
Share this answer
 
v2
Comments
CHill60 3-Dec-13 16:22pm    
Not sure if this is meant to be a solution or a further question as I'm struggling to understand your words. If this is meant as an addition to your question then use the Improve Question link then delete this solution - by posting a solution you have made your question drop out of the list of unanswered questions, therefore fewer people will see it.
A word of advice ... "d" is very hard for non-English speakers to understand ... use "the"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900