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

How to compare same column and multiple values in same table?

Table1 fields and datas : (itemcode,itemdesc)
(101, aaa)
(102, bbb)
(103, ccc)
(104, eee)
(105, fff)
(106, ggg)
(107, hhh)

Table2 fields and datas : (itemcode, finperiod, finyear)
(101, 'jan-14', fy2014)
(101, 'feb-14', fy2014)
(102, 'jan-14', fy2014)
(102, 'feb-14', fy2014)
(103, 'jan-14', fy2014)
(104, 'feb-14', fy2014)
(105, 'mar-14', fy2014)
(101, 'mar-14', fy2014)
(102, 'feb-14', fy2014)

Query like this : To get itemcode where finperiod='jan-14' not in finperiod='feb-14'and finyear='fy2014' and itemdesc = 'aaa';

if above query executes then the output should be like this : 103.

I got this output but I used to separate this two table into multiple table that means to split tables like a_jan, a_feb, a_mar...
Apr 20 '15 #1

✓ answered by Rabbit

So if you're dropping the itemdesc criteria, then that makes more sense. When you had the data split into multiple tables, you probably used an outer join to find what you needed correct? You can do the same thing. Except you just join the table to itself and include the criteria in the join.

5 1679
Rabbit
12,516 Expert Mod 8TB
I don't understand what you're trying to do. What you say the criteria is doesn't match the results you gave. 103 has a description of ccc and yet you say you only want a description of aaa.
Apr 20 '15 #2
I mean whatever itemcode I use in finperiod = 'jan-14' and also I use same itemcode in finperiod = 'feb-14'. Sometimes, I don't use same itemcode whatever I used in finperiod = 'jan-14'. I need the output for that unused itemcode. Ex: (103, 'jan-14', 'fy2014') this same itemcode I don't use for finperiod = 'feb-14'. So the output is : 103.
Apr 21 '15 #3
Rabbit
12,516 Expert Mod 8TB
So if you're dropping the itemdesc criteria, then that makes more sense. When you had the data split into multiple tables, you probably used an outer join to find what you needed correct? You can do the same thing. Except you just join the table to itself and include the criteria in the join.
Apr 21 '15 #4
That is my problem. I don't know how to write join query for this criteria.
Apr 21 '15 #5
Rabbit
12,516 Expert Mod 8TB
It would be something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2. FROM
  3.    tableName AS t1
  4.  
  5.    LEFT JOIN tableName AS t2
  6.    ON t1.IDField = t2.IDField
  7.    AND t2.ValueField = 'value you don't want'
  8.  
  9. WHERE
  10.    t1.ValueField = 'value you do want' AND
  11.    t2.IDField IS NULL
Apr 21 '15 #6

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

Similar topics

1
by: Bill | last post by:
I have a column of digits I'd like to copy into another column in the same table. How would I do this? Thanks, Bill
2
by: Larry Bird | last post by:
I have a datatable that was created within a dataset. I dynamically add columns to the table as I add data. Previously added rows probably did not have data for the column that is being added. ...
4
by: khengi | last post by:
Hi, I'm a newbie, so I guess this is a question that expresses my total ignorance, but never the less: I have an old table into which I want to add a column that will automatically update based...
3
by: Manikandan | last post by:
Hi, I have table with three columns as below table name:exp No(int) name(char) refno(int) I have data as below No name refno 1 a 2 b 3 c
2
by: amitsaxena1981 | last post by:
hi, I am using asp.net2.0 with vb.net , I have to create gridview user control and I want to drag and drop a record to a different position in the same Gridview using AJAX .Is it possible to...
1
by: abinesh.agarwal | last post by:
Hi , I want to update the column in a table based on the updation of the other column in the same table, but not getting the desired result. DDL: CREATE TABLE .( NULL,
3
by: cubekid | last post by:
Dev't Tool: Visual C# 2003 and Javascript System Type: Web Application One requirement of the system is to dynamically create a table on client-side (Javascripting using createElement method.)...
1
by: Nishant Gaurav | last post by:
Hi All, Here is the scenario i want a solution for. i have two columns col1 and col2 which needs to access the result of same table whose col(say time col) is required for fetching the result....
1
by: praveenakarthi | last post by:
Hello All, I need to combine more than one column and display it next line. eg: sno name address company city 1 Bujju India Advent ...
4
by: michaeldebruin | last post by:
Hello everyone, I am having the following issue: The company for which I am working for got an MySQL table which I need to clean up. But it also contains some important data. So I need to check...
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
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?
0
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...
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
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...

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.