if suppose i am having an ACCOUNT table with 3 coloumns ACC.
NO,ACC. NAME,ACC. AMOUNT . If a unique index is also
defined on ACC.NO and ACC.NAME then write a query to
retrieve account holders records who have more than 1 ACC.
Answers were Sorted based on User's Feedback
Answer / ram prajapati
sir,
is it possible to have duplicate values for a uniquely
defined column.........or ... is it possible to define a
unique index on a column which is not having unique value?
plz help me out..
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / mallikarjun
select distinct ACC.NO,
ACC. NAME,
ACC. AMOUNT
from account
where acc.name in
( select distinct acc.name
from account
group by acc.name
where count(acc.no) > 1)
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / s
For this scenario duplicate records will not exist in the
table as the index has been defined on the 2 primary keys.
Hence the answer is we can't pull the account holders
having more than 1 account
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / suleman
Try this one
select ACC.NO,ACC.NAME
FROM ACCOUNT
group by ACC.NO
HAVING COUNT(*) > 1
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / lol
select ACC.NO||ACC.Name from ACCOUNT having count(acc.no||acc.name) >1
| Is This Answer Correct ? | 0 Yes | 0 No |
Hi All,
Here u already have a unique index defined on ACC.NO and ACC.NAME feilds.
Unique index will not allow more than one value for this particular field (Correct me if I am wrong).
Then hw can we get more that one a/c no for a person in this scenario ?
So the answer will be, u can not store more than one a/c number for a person since u have a unique indexes on these table.
Regards,
Ratheesh Nellikal
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / rihaan
Thanks a lot Mr.Mallikarjun but the inner query u wrote
alone does the work.
kindly check it up
| Is This Answer Correct ? | 0 Yes | 2 No |
How to resolve -407 sql code in DB2?
What techniques are used to retrieve data from more than one table in a single SQL statement?
What does it mean if the null indicator has -1, 0, -2?
Consider that a package is bound into 2 different collections and the PKLIST option specifies both the collections. If the collection id is not specified in the program while executing the SQL query, then when the DB2 system will search the package list, which collection will it pick up or will it give an error/abend?
Cursors can be declared in both working-storage & procedure division, agreed. But is there any difference? If could you please suggest what is the difference
Can one database have multiple instances?
explain about index with examples
What are the various locking levels available?
Mention and explain the contention situations caused by locks?
What is the maximum size of a char data type in db2?
if there is a table with huge number of records and if i want to extract only first 3 records from the table, what query i have to provide to retreive first 3 records
What is a NULL value? What are the pros and cons of using NULLS?