473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to select from two rows with same information but one clumn data is diffren

Name designation promotedto newdestin
Dr Dharam Raj Singh Scientist 22 Jan 2008 Scientist S.S
Dr Dharam Raj Singh Scientist 22 Jan 2010 Scientist S.S

how i wl select one row from there two rows.
this is an eg. in mine table there is lots of rows of this type

thanks
May 7 '07 #1
8 5785
pbmods
5,821 Expert 4TB
You're probably looking for something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT * FROM `tableName` GROUP BY `name`;
  2.  
May 8 '07 #2
sorry sir ur query is not working i think u haven't seen my query there is a column with disimilar data but name is the same.
pls
chek it and reply me
You're probably looking for something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT * FROM `tableName` GROUP BY `name`;
  2.  
May 8 '07 #3
pbmods
5,821 Expert 4TB
sorry sir ur query is not working i think u haven't seen my query there is a column with disimilar data but name is the same.
I'm not sure I understand how your table is set up. I think it looks something like this:

Expand|Select|Wrap|Line Numbers
  1. Name                designation        promotedto        newdestin
  2. -------------------        -----------        -----------        -------------
  3. Dr Dharam Raj Singh        Scientist        22 Jan 2008        Scientist S.S
  4. Dr Dharam Raj Singh        Scientist        22 Jan 2010        Scientist S.S
  5.  
SELECT DISTINCT will only show one row when it encounters multiple rows that have the same value in the GROUP BY clause. So if you wanted to get unique names, you would use the query I provided in the last post (though you'd probably need to change `tableName` to the whatever your table is actually named).

If you had people with the same name, and you wanted to differentiate further, you might need to add another column to the GROUP BY clause (e.g., SELECT DISTINCT * FROM `tableName` GROUP BY `name`, `designation`).
May 8 '07 #4
thanks brother for ur reply
but i think u don't understand my problem:
now i am paste my query and output here:

query:

Select title+' '+UPPER(SUBSTRING(FirstName,1,1)) + LOWER(SUBSTRING(FirstName,2,LEN(FirstName)))+' '+
UPPER(SUBSTRING(MidName,1,1)) + LOWER(SUBSTRING(MidName,2,LEN(MidName)))+' '+
UPPER(SUBSTRING(LastName,1,1)) + LOWER(SUBSTRING(LastName,2,LEN(LastName))) as name,d.desg_name as olddesignation,
CONVERT(CHAR(11),dateadd(yy,pd.yearsexp,p.dt_last_ prom),106) as promotiondue,
d1.desg_name as newdesignation
From personnel p,promotiondue pd,qualification q,designation d,designation d1
where p.Ser_Type= 'S' and p.I_code= 83
and p.desg_code=pd.desgcode and p.emp_code=q.emp_code and q.qual_Type=pd.educriteria
and pd.desgcode = d.desg_code and pd.promotedto = d1.desg_code
and getdate() < dateadd(yy,pd.yearsexp,p.dt_last_prom)
order by name


output:


name olddesgintaion promotedto newdesignation
Dr Dharam Raj Singh Scientist 22 Jan 2010 Scientist S.S
Dr Dharam Raj Singh Scientist 22 Jan 2008 Scientist S.S
Dr Rajender Parsad Sr.Scientist 23 Jan 2009 Principal Scientist
Dr Seema Jaggi Sr.Scientist 21 Jan 2009 Principal Scientist
Dr Sushila Kaul Sr.Scientist 29 May 2008 Principal Scientist
Mr Hukum Chandra Scientist S.S 19 Dec 2007 Scientist S.G
Smt Alka Arora Scientist S.S 27 Nov 2008 Scientist S.G


in this query dharam raj has done two degreee (msc and phd) .first record show on the basis of msc and second record show on the basis of phd. but i want that only phd record is show there not firstone.


pls help me yaar i m really confuse how to solve this problem.
reply me soon








I'm not sure I understand how your table is set up. I think it looks something like this:

Expand|Select|Wrap|Line Numbers
  1. Name                designation        promotedto        newdestin
  2. -------------------        -----------        -----------        -------------
  3. Dr Dharam Raj Singh        Scientist        22 Jan 2008        Scientist S.S
  4. Dr Dharam Raj Singh        Scientist        22 Jan 2010        Scientist S.S
  5.  
SELECT DISTINCT will only show one row when it encounters multiple rows that have the same value in the GROUP BY clause. So if you wanted to get unique names, you would use the query I provided in the last post (though you'd probably need to change `tableName` to the whatever your table is actually named).

If you had people with the same name, and you wanted to differentiate further, you might need to add another column to the GROUP BY clause (e.g., SELECT DISTINCT * FROM `tableName` GROUP BY `name`, `designation`).
May 10 '07 #5
brother i had make new table check1
with field
name
id

data is
name id
amit 1 // i don't need this record
amit 3 // i need this record
ravi 5
anil 7


but when i exeucted ur query then ur query give error:
Column 'check1.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

ur query is what i executed :
select distinct * from check1 group by name



I'm not sure I understand how your table is set up. I think it looks something like this:

Expand|Select|Wrap|Line Numbers
  1. Name                designation        promotedto        newdestin
  2. -------------------        -----------        -----------        -------------
  3. Dr Dharam Raj Singh        Scientist        22 Jan 2008        Scientist S.S
  4. Dr Dharam Raj Singh        Scientist        22 Jan 2010        Scientist S.S
  5.  
SELECT DISTINCT will only show one row when it encounters multiple rows that have the same value in the GROUP BY clause. So if you wanted to get unique names, you would use the query I provided in the last post (though you'd probably need to change `tableName` to the whatever your table is actually named).

If you had people with the same name, and you wanted to differentiate further, you might need to add another column to the GROUP BY clause (e.g., SELECT DISTINCT * FROM `tableName` GROUP BY `name`, `designation`).
May 10 '07 #6
pradeep kaltari
102 Expert 100+
brother i had make new table check1
with field
name
id

data is
name id
amit 1 // i don't need this record
amit 3 // i need this record
ravi 5
anil 7


but when i exeucted ur query then ur query give error:
Column 'check1.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

ur query is what i executed :
select distinct * from check1 group by name
Hi Nittin,
You are getting that error because you are doing a select distinct * on the table grouped by the name. The table has two different entries for the same name "amit" and the result after executing GROUP BY Name should give only one entry for each name, hence the error.

Please let us know if you have any other field in the table based on which you want the record for "amit" with id 3.

If you are using a GROUP BY clause then all the columns you want to SELECT (other than aggregate functions) need to be specified in the GROUP BY clause as well.

Regards,
Pradeep
May 10 '07 #7
Hi nittin,
I too had the same problem . you please check with exists function. see my replies in the following url
[HTML]http://www.thescripts.com/forum/thread641242.html[/HTML]
May 10 '07 #8
helo brother


how r u .
i got the solution.
the solution is if there is two record of the same name then in asp.net use varreader. when they read one by one put if condition there then if condition is true store it in a datatable otherwise not atlast bind it with datalist.

if u need more ans. then tell me i wl give

thanks for ur corparatae




Hi nittin,
I too had the same problem . you please check with exists function. see my replies in the following url
[HTML]http://www.thescripts.com/forum/thread641242.html[/HTML]
May 14 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
10
by: AC Slater | last post by:
I have 1 table (out of many) that has very poor performance when performing a select into on. The select statement is called multiple times. We've found each call to take almost 1 second... we...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
33
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some...
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
3
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I'm not really sure how to ask this question because I'm still getting my feet wet with data access and VB.NET, but here goes: To start off with, I'm using VB 2005 Express to connect to an Access...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.