473,385 Members | 2,210 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,385 software developers and data experts.

***Sql Query problem

hi I have the data in sql server table like

OrderID Trans ID
74 1
74 4
74 5
76 1
76 4
76 5
here please observe TransID 1,4,5 is repeating in all the orderID
Field.In my table some of the order's have the value "1" but not have
"5".We need to find the orders id's which are having 1 for that order
id and not having the value 5.Please send me a query for this

Thanks,
Srui

Dec 26 '05 #1
6 2804
srinivas wrote:
hi I have the data in sql server table like

OrderID Trans ID
74 1
74 4
74 5
76 1
76 4
76 5

here please observe TransID 1,4,5 is repeating in all the orderID
Field.
Pardon?
In my table some of the order's have the value "1" but not have
"5".We need to find the orders id's which are having 1 for that order
id and not having the value 5.Please send me a query for this


Wrong newsgroup.

However, the condition "value '1' and not value '5'" contains a redundancy.
What is 1 is always not 5:

SELECT OrderID FROM a WHERE 'Trans ID' = 1 GROUP BY 1

Maybe you mean "value 1 _or_ not 5":

SELECT OrderID FROM a WHERE 'Trans ID' != 5 GROUP BY 1
PointedEars
Dec 26 '05 #2
Thomas 'PointedEars' Lahn said the following on 12/26/2005 3:26 PM:
srinivas wrote:

hi I have the data in sql server table like

OrderID Trans ID
74 1
74 4
74 5
76 1
76 4
76 5

here please observe TransID 1,4,5 is repeating in all the orderID
Field.

Pardon?

In my table some of the order's have the value "1" but not have
"5".We need to find the orders id's which are having 1 for that order
id and not having the value 5.Please send me a query for this

Wrong newsgroup.

However, the condition "value '1' and not value '5'" contains a redundancy.
What is 1 is always not 5:

SELECT OrderID FROM a WHERE 'Trans ID' = 1 GROUP BY 1

Maybe you mean "value 1 _or_ not 5":


No, it reads "value 1 _and_ not 5".

OrderID 74 has three Trans ID's, 1, 4 and 5.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 26 '05 #3
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 12/26/2005 3:26 PM:
However, the condition "value '1' and not value '5'" contains a
redundancy. What is 1 is always not 5:

SELECT OrderID FROM a WHERE 'Trans ID' = 1 GROUP BY 1

Maybe you mean "value 1 _or_ not 5":
No, it reads "value 1 _and_ not 5".


The condition

'Trans ID' = 1 AND 'Trans ID' != 5

contains a redundancy because everything that is equal to 1 is always
not equal to 5. So that condition does not really make sense. Instead,
an OR makes more sense, for the query result would contain _additional_
data then (hence the misuse/non-logical use of "and").
OrderID 74 has three Trans ID's, 1, 4 and 5.


So? Either query I provided will return those ...
PointedEars
Dec 26 '05 #4
Thomas 'PointedEars' Lahn said the following on 12/26/2005 5:17 PM:
Randy Webb wrote:

Thomas 'PointedEars' Lahn said the following on 12/26/2005 3:26 PM:
However, the condition "value '1' and not value '5'" contains a
redundancy. What is 1 is always not 5:

SELECT OrderID FROM a WHERE 'Trans ID' = 1 GROUP BY 1

Maybe you mean "value 1 _or_ not 5":
No, it reads "value 1 _and_ not 5".

The condition

'Trans ID' = 1 AND 'Trans ID' != 5

contains a redundancy because everything that is equal to 1 is always
not equal to 5.


Not when the item has multiple Trans ID's which is what the posted data
shows:

OrderID Trans ID
74 1
74 4
74 5

So, if OrderID # 80 looked like this:

OrderID Trans ID
80 1
80 4

Then 80 should qualify as it contains 1 but does not have a Trans ID of
5. But orderID # 74 shouldn't qualify as it has 1 but also has 5.

It is the same scenario as if OrderID was a FlightNum and TransID was
layover sites on a plane flight. If you want all the flights from New
York to Moscow that do not layover in London but do layover in Paris
then its "Yes London AND Not Paris".
So that condition does not really make sense.
Sure it does. Re-read it though.
Instead, an OR makes more sense, for the query result would contain
_additional_ data then (hence the misuse/non-logical use of "and").
The OP is wanting to minimize data, not have additional data.
OrderID 74 has three Trans ID's, 1, 4 and 5.

So? Either query I provided will return those ...


Since this is a javascript group, I won't comment on potential SQL queries.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Dec 26 '05 #5
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 12/26/2005 5:17 PM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 12/26/2005 3:26 PM:
However, the condition "value '1' and not value '5'" contains a
redundancy. What is 1 is always not 5:

SELECT OrderID FROM a WHERE 'Trans ID' = 1 GROUP BY 1

Maybe you mean "value 1 _or_ not 5":
No, it reads "value 1 _and_ not 5".


The condition

'Trans ID' = 1 AND 'Trans ID' != 5

contains a redundancy because everything that is equal to 1 is always
not equal to 5.


Not when the item has multiple Trans ID's which is what the posted data
shows:

OrderID Trans ID
74 1
74 4
74 5

So, if OrderID # 80 looked like this:

OrderID Trans ID
80 1
80 4

Then 80 should qualify as it contains 1 but does not have a Trans ID of
5. But orderID # 74 shouldn't qualify as it has 1 but also has 5.


SELECT DISTINCT OrderID FROM trans WHERE Trans_ID = 1 AND OrderID
NOT IN (SELECT DISTINCT OrderID FROM trans WHERE Trans_ID = 5);
OrderID 74 has three Trans ID's, 1, 4 and 5.

So? Either query I provided will return those ...


Since this is a javascript group, I won't comment on potential SQL
queries.


Since I have tested successfully this in MySQL Ver 14.12 Distrib 5.0.16:
X-Post & Followup-To comp.databases.mysql

PointedEars
Dec 26 '05 #6
Guy
srinivas a écrit :
hi I have the data in sql server table like

OrderID Trans ID
74 1
74 4
74 5
76 1
76 4
76 5
here please observe TransID 1,4,5 is repeating in all the orderID
Field.In my table some of the order's have the value "1" but not have
"5".We need to find the orders id's which are having 1 for that order
id and not having the value 5.Please send me a query for this

Thanks,
Srui

Bonjour,

try :

select A.OrderId from Table A
where A.TransID=1 and A.OrderID not in (Select B.OrderID from Table B
where B.TransID=5 )

(and respect type of data)

GR
Dec 27 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
5
by: Matt | last post by:
Hello I am running a SP from the SQL Server Agent, the job has one step that looks like this. exec q_spr_inlevextsystem This job fails with the following message Job 'AutoInlev' : Step...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
9
by: Christine | last post by:
It has come to my attention that sometimes, when I open a Query in SQL View, the SQL that I see is not exactly the same as the SQL in the Query's Querydef. The difference I see (only occasionally)...
0
by: Tony Epton | last post by:
I am not quite a newbie in the area of SQL server - more "knows just enough to be dangerous" - so please be gentle with me. Cross posted to several groups - apologies if too far off topic I...
3
by: Martini | last post by:
Hello all. I have quite disturbing situation where I am not happy about the way how SQL handles the query. Situation is related to using user function in INNER JOIN select. Although the problem...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
6
by: Twobridge | last post by:
I hope someone can help me out with my problem. I have found a sql statement that basically pulls all bills filed within a certain time period and the payments made on those bills with in the...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.