473,795 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compare column value of two row of same table

1 New Member
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 24650
r035198x
13,262 MVP
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
vanroojdotcom
1 New Member
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=f ord

Is that correct?
Jun 12 '07 #3
mark roles
2 New Member
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
mark roles
2 New Member
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
5129
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 for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
5
10882
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 new database. For instance, her old database has a table with Band Info in it. Her new database also has a table with Band Info in it but slightly different. I was wondering if there was an easy way to compare the fields from similar tables in...
2
9965
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, update the SQL Server table with said changes. The datasets are about 2000 rows. My thinking is performing a check row by row is inefficient, so I thought about how I could compare the two as datasets and resolve differences. The SQL Server table...
0
1584
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 havent been able to get the sample to work. I notice the cursor cycling through the Excel records, but the SQL table always shows up empty. Notice anything wrong here?
17
4534
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 selected into 2 different SP variables and compared for equal. They are both NULL, but do not compare as equal. When the Not NULL columns (SALARY) are compared, they do compare as equal.
11
35427
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 amount of rows in theese datatables . So i don 't want to enumerate each rows. This is not efficient and unacceptable for my current application.
3
9262
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 to do is compare the values in the column 'Shift_Date' for the maximum value of Row_Index and the (maximum value - 1) of Row_Index. I've been trying to declare two strings, setting each string equal to one of my values, and then comparing the...
3
1686
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 excel from only one column with every row of my access table from only one column of the same type. For examle: My excel has 3 columns: Code, Name, City. My access table has 4 columns: Code, Name, City, Country.
1
2380
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, table.tons_trk FROM table WHERE (((table.Record_Date)>=#8/28/2008 6:15:00#)) ORDER BY table.excav_id, table.RecordID, table.indx_dpr,table.Record_Date; In the query result below, the value in the column ‘tons_trk’ is the running total of the ‘tons_bkt’...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.