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

Sort data under 1 table but with different data

Hi...

I'm the new comer in this scripts network. Also quite new in SQL coding.
I would like to ask some sql scripts.

Eg. I have a table as belows :
Item Warehouse
---------------------------------
BTN001 070
BTN001 073
BTN002 070
BTN003 073
BTN004 070
BTN004 073

Then the result I want is only for item BTN002.
That means I only want to sort out item which is existed in 070, but not exist in 073.
But not the other way. I don't need item which is existed in 073, but not exist in 070.
So, how is the sql scripts for above ? Kindly help.

Thanks a lot.
Sep 10 '07 #1
6 1375
r035198x
13,262 8TB
Hi...

I'm the new comer in this scripts network. Also quite new in SQL coding.
I would like to ask some sql scripts.

Eg. I have a table as belows :
Item Warehouse
---------------------------------
BTN001 070
BTN001 073
BTN002 070
BTN003 073
BTN004 070
BTN004 073

Then the result I want is only for item BTN002.
That means I only want to sort out item which is existed in 070, but not exist in 073.
But not the other way. I don't need item which is existed in 073, but not exist in 070.
So, how is the sql scripts for above ? Kindly help.

Thanks a lot.
Hi and welcome to TSDN.
Try

Expand|Select|Wrap|Line Numbers
  1. select * from tableName where Warehouse = 070 and Item not in (select Item from tableName where Warehouse <> 070) 
Sep 10 '07 #2
Hi and welcome to TSDN.
Try

Expand|Select|Wrap|Line Numbers
  1. select * from tableName where Warehouse = 070 and Item not in (select Item from tableName where Warehouse <> 070) 
Hi...

Thanks a lot for the quick reply. I just try it with my winSQL, but it just didn't work.
THere's no data sort out. Could you please advise furthermore ?

Thanks a lot.
Sep 10 '07 #3
Hi...

Thanks a lot for the quick reply. I just try it with my winSQL, but it just didn't work.
THere's no data sort out. Could you please advise furthermore ?

Thanks a lot.
Hi...

I try to change some of the code and found below code work :
Expand|Select|Wrap|Line Numbers
  1.  SELECT * FROM tableName WHERE Warehouse = 070 AND Item NOT IN (SELECT Item FROM tableName WHERE Warehouse = 073)
  2.  
So, it should be ok now.. THanks a lot for the guidelines.... ^_^
Sep 10 '07 #4
r035198x
13,262 8TB
Hi...

I try to change some of the code and found below code work :
Expand|Select|Wrap|Line Numbers
  1.  SELECT * FROM tableName WHERE Warehouse = 070 AND Item NOT IN (SELECT Item FROM tableName WHERE Warehouse = 073)
  2.  
So, it should be ok now.. THanks a lot for the guidelines.... ^_^
What if you have a third warehouse, say 074 and want the items only in 070 ?

I think you should try to get the statement with not equal to 070 to work. What error did you get when you tried it?
Sep 10 '07 #5
amitpatel66
2,367 Expert 2GB
Hi...

I'm the new comer in this scripts network. Also quite new in SQL coding.
I would like to ask some sql scripts.

Eg. I have a table as belows :
Item Warehouse
---------------------------------
BTN001 070
BTN001 073
BTN002 070
BTN003 073
BTN004 070
BTN004 073

Then the result I want is only for item BTN002.
That means I only want to sort out item which is existed in 070, but not exist in 073.
But not the other way. I don't need item which is existed in 073, but not exist in 070.
So, how is the sql scripts for above ? Kindly help.

Thanks a lot.
Expand|Select|Wrap|Line Numbers
  1. SELECT e.* FROM <table_name> e WHERE e.warehouse = '070' AND 1 = (SELECT COUNT(warehouse) FROM <table_name> WHERE item = e.item)
  2.  
Sep 10 '07 #6
What if you have a third warehouse, say 074 and want the items only in 070 ?

I think you should try to get the statement with not equal to 070 to work. What error did you get when you tried it?
Hi...

Actually the original data has more than 1 warehouse.. And by using the modification sql, it works also. So it's ok already now.
BY using the 1st sql, I didn't get any error msg, only there's no data sort out.
But using the 2nd sql that I've modified from yours, success...
So, thanks a lot..
Sep 11 '07 #7

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

Similar topics

1
by: web developer | last post by:
hi i got a query that takes about 14 mins here it is select BDProduct.ProductCode,BDProduct.ProductName,SALTerritory.TerritoryID...
9
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a...
2
by: none | last post by:
I run a web site that searches for data on other web sites and displays the results for the user onscreen. Currently, it uses perl to fetch the data, sort it and display it. It can take quite a...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
1
by: Lyners | last post by:
I am trying to figure out the best way to do this (currently I am having a problem sorting). I have a vb.net program that contains 2 datagrids on a form for the end user. When the user is ready to...
6
by: Les Juby | last post by:
I need to extract records from a database subject to conditions and only thereafter give the users the choice of which fields to sort the results on. In this situation I can't write back to a...
6
by: weetat.yeo | last post by:
Hi all , I have sql statement below , SELECT serial_no,host_name,chasis_model,chasis_flash_size,chasis_dram_size,...
3
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Are there any good built-in or availble functions that I can call to sort my dataset datatalbe based on 1 or more of the table's columns? -- Thanks.
5
by: neocortex | last post by:
Hello! I am a newbie in Python. Recently, I get stuck with the problem of sorting by two criteria. In brief, I have a two-dimensional list (for a table or a matrix). Now, I need to sort by two...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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...
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
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...

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.