473,395 Members | 1,870 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,395 software developers and data experts.

How to compare column value of two row of same table

comapre column value of two row of same table. suppose in table tabl1 have column name comn1 it has two row means two value... after comparison i have to return some value like true or false...................

So tell me any in-built function is there in MS-sql.................
Jun 12 '07 #1
4 24614
r035198x
13,262 8TB
comapre column value of two row of same table. suppose in table tabl1 have column name comn1 it has two row means two value... after comparison i have to return some value like true or false...................

So tell me any in-built function is there in MS-sql.................
I havebeen re-reading your post again and again. Let me try to describe your problem again. You have one table with two rows. The table has a column called, say, comn1. And you want a query that returns true if the two rows have the same value in comn1?
Jun 12 '07 #2
I think I understand what you mean.

you have one table and three fields - let's say

1) MAKE OF CAR (Page Heading)
2) COLOUR OF CAR (The make's description)
3) THIS MAKE IS OWNED BY (a dynamic link back to a parent company)

So a few entries may be
A - 1) Jaguar 2) Green 3) Ford
B - 1) Peugeot 2) Grey 3) Citroen-Peugeot
C - 1) Ford 2) Brown 3) NULL (Ford owns Ford) so it's blank

What you want is to match WHERE (3) = (1) but not in the same row (they never will and no matter what you do there is never a return). What you want is for the query to match over different rows ONLY so the database looks and sees that Field (3) = Field (1) in ROW A and returns the URL value Ford (which you can then use as a value to link to the Company "FORD" on page C. www.cars.com/cars.php?make=ford

Is that correct?
Jun 12 '07 #3
This was never answered, but I would like to know how, as in the example with the “CAR” example shown above.
Oct 26 '10 #4
Here is what I came with to solve this senario:

+--------------------+
| tblName |
+--------------------+
+------+------+------+
| ID | C1 | C2 |
|------|------|------|
|------|------|------|
| 1 | a | x |
|------|------|------|
| 2 | b | c |
|------|------|------|
| 3 | c | f |
|------|------|------|
| 4 | d | z |
|------|------|------|
| 5 | e | q |
|------|------|------|
| 6 | f | a |
+------+------+------+

SO QUERY RESULTS WOULD BE = ID 1 & 6, ID 3 & 2, ID 6 & 3.




select a.ID, b.ID
from tblName a
join tblName b
on a.c1 = b.c2;

+------+------+
| id | id |
+------+------+
| 3 | 2 |
| 6 | 3 |
| 1 | 6 |
+------+------+
Oct 30 '10 #5

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

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
2
by: codejockey | last post by:
I have a simple project that requires I take a set of data from an Excel spreadsheet, compare it to a table in SQL Server (where column names match), and if there are changes in the Excel sheet,...
0
by: codejockey | last post by:
Please forgive the repost, but I'm trying to avoid the hack I want to implement since I cant get this sample to work. Can anyone help? *********************** William: Thanks for the reply. I...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
3
by: mcolson | last post by:
I am trying to compare the last two values in the same column of a table. First of all, I have a column titled Row_Index that uses an index which starts at 1 and increments by 1. What I am trying...
3
by: pochimen | last post by:
Hi everyone, i`m trying to make access interact with excel in vba I have an excel sheet with 3 columns and 30 rows, and an access table of 4000 rows. The idea is to compare every row of the...
1
by: BigH | last post by:
I am using the following sql query via ODBC to pull data from a database into Access. SELECT table.excav_id, table.RecordID, table.indx_dpr, table.tons_bkt, ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.