[Show all top banners]

hurray
Replies to this thread:

More by hurray
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 SQL help
[VIEWED 5207 TIMES]
SAVE! for ease of future access.
Posted on 02-11-05 7:59 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I have a table with data in following order.

ID Career Term Bill_Career

A GR 50 GR
B UGR 50 UGR
C UGR 50 UGR
D GR 50 GR
E UGR 50 UGR
A UGR 50 GR
B GR 50 GR
C GR 50 GR

What I am looking for is, any ID that occures twice with Different Bill_Career.
How can I make the output look like

ID Career Term Bill_Career

B UGR 50 UGR
B GR 50 GR
C UGR 50 UGR
C GR 50 GR

 
Posted on 02-11-05 9:13 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

SELECT DISTINCT ID_CARRER_TERM_BILL_CAREER , B UGR , C UGR FROM TABLENAME

Distinct key word has to be used before the column name to eliminate the duplicate values

eg

Select disctinct columname, column from table name where condition.

 
Posted on 02-11-05 9:32 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


SELECT B UGR 50 UGR,
B GR 50 GR,
C UGR 50 UGR,
C GR 50 GR FROM TableName;
 
Posted on 02-11-05 9:42 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

>What I am looking for is, any ID that occures twice with Different Bill_Career.

It means u r looking for a Unique ID ? Is it?
My answer would be similar to usof but You say you are looking for ID that comes twice?
Would you make your question a lil bit clear?
 
Posted on 02-11-05 9:49 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hurray, Here is the answer.

select a.id,a.career, a.term, a.bill_career
from rg_semester a, /* this rg_semester table is assumption */
rg_semester b
where
a.id = b.id
and a.bill_career != b.bill_career
and a.id in (select a.id from rg_semester
group by a.id having count(a.id)>1);


ID CAREER TERM BILL_CAREE
-- ---------- ----- ----------
B GR 50 GR
B UGR 50 UGR
C GR 50 GR
C UGR 50 UGR

Good Luck.
 
Posted on 02-11-05 9:51 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Select ID_Career, Bill_term_career
From TableName
Group by ID_Career

Try this and see if it helps.. Let me know too. I will try other query's if this is not what you are looking for.
 
Posted on 02-11-05 9:52 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Think Aryan has nailed it.
 
Posted on 02-11-05 9:55 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

if you want to retrive the distinct colums from table then

SELECT DISTINCT ID Career from TableName
Where IDCareer IN ('B','c');

or
SELECT DISTINCT ID career from Tablename
whrere IDCareer like "%b" and "%c";

i am not sure though... just try it...
 
Posted on 02-11-05 9:56 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

select a.id,a.career, a.term, a.bill_career
from rg_semester a, /* this rg_semester table is assumption */
rg_semester b
where
a.id = b.id
and a.bill_career != b.bill_career
and a.id in (select a.id from rg_semester
group by a.id having count(a.id)>1);


ID CAREER TERM BILL_CAREE
-- ---------- ----- ----------
B GR 50 GR
B UGR 50 UGR
C GR 50 GR
C UGR 50 UGR

great!
 
Posted on 02-11-05 9:58 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

usofa,

if there are 100000 of row, how would you know only 'B' & 'C' id have distinct values in bill_career? The logic wouldn't work. Just my two cents.
 
Posted on 02-11-05 10:00 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Aryan, I am not sure but yours looks right to me.
The way I figured out was :

select A.*
from tablename A, tablename B
where A.ID = B.ID
and A.term = B.term
and A.bill_career <> B.bill_career


Anyway, thanks to everyone.
 
Posted on 02-11-05 10:04 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

the last statement should be
A.bill_career <> B.bill_career
 
Posted on 02-11-05 10:05 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

not equal

Sajha doesn't let me put that sign
 
Posted on 02-11-05 10:07 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you can put not equal sign different ways.
!= OR <> OR ^=

 
Posted on 02-11-05 10:23 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I agree with Aryan's Query
 
Posted on 02-11-05 11:22 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Can someone explain it in english. The operators, statement etc
 
Posted on 02-11-05 2:13 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

The commonl logical operators are
AND,
OR ,
NOT.
there are other types of operators as well. they can be classified as followes.
Comparison Operators
mathematical functions and Ooperators
string Functions and Operators
Binary String Functions and Operators
Pattern Matching

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
All the Qatar ailines from Nepal canceled to USA
Travel Document for TPS (approved)
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters