Need help to write a MySQL query that returns only the peer matching records
Because I don't know how to explain it easily, I use the table below as an example.I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.
Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.
How can I create a query that will do it?
ID | col1 | col2
--------------------
1. ABC | DEF
2. DEF | ABC
3. ABC | IGS
4. DEF | IGS
5. IGS | DEF
* Please let me know if you have no idea of what I'm trying to explain.
I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.
SELECT a.col1,
a.col2
FROM table_name AS a
LEFT OUTER
Table_name JOIN b
ON b.col1 = a.col2
AND a.col1 = b.col2
WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.
Tags: Dreamweaver
Similar Questions
-
Need help to write a sub query
Our environment - Oracle 10 g
Hi all
Need help to write a sub query to reach him here are examples of data using which iam trying to replace the value column in the table based on two other columns in the same table
Examples of data
ClaimNo flag LineNo Procedurecode
100 01 N MN4567
100 02 Y 7863
100 03 N MN8976
100 04 Y 9000
101 01 Y 8954
101 02 N MN6754
101 03 N MN7654
101 04 Y 8976
102 01 Y 1234
102 02 Y 2345
102 03 Y 3456
102 03 Y 4567
Each column of ClaimNo has several rows of data. But if column procedurecode for a claimNo starts with MN then all values associated with the claimno for the flag column should replace N
If the data must become like below
ClaimNo flag LineNo Procedurecode
100 01 N MN4567
100 02 N 7863
100 03 N MN8976
100 04 N 9000
101 01 N 8954
101 02 N MN6754
101 03 N MN7654
101 04 N 8976
102 01 Y 1234
102 02 Y 2345
102 03 Y 3456
102 03 Y 4567
Thank youSee the example:
with t as ( select 100 ClaimNo, '01' LineNo, 'N' Flag, 'MN4567' Procedurecode from dual union all select 100, '02', 'Y', '7863' from dual union all select 100, '03', 'N', 'MN8976' from dual union all select 100, '04', 'Y', '9000' from dual union all select 101, '01', 'Y', '8954' from dual union all select 101, '02', 'N', 'MN6754' from dual union all select 101, '03', 'N', 'MN7654' from dual union all select 101, '04', 'Y', '8976' from dual union all select 102, '01', 'Y', '1234' from dual union all select 102, '02', 'Y', '2345' from dual union all select 102, '03', 'Y', '3456' from dual union all select 102, '03', 'Y', '4567' from dual ) select claimno, lineno, flag, case when count(decode(substr(procedurecode,1,2),'MN',1)) over(partition by claimno)>0 then 'N' else flag end new_flag, procedurecode from t
Kind regards
Sayan M. -
Need help to write a SQL query complex
I have the source tabe as below
-> SOURCE_TABLE
I want to load as target table belowNAME CUST_ID SVC_ST_DT SVC_END_DT TOM 1 31/08/2009 23/03/2011 DOCK 2 01/01/2004 31/05/2010 HARRY 3 28/02/2007 31/12/2009
-> TARGET_TABLE
Is it possible to write a SQL query that returns the data in the same way above the target table.NAME CUST_ID SVC_ST_DT SVC_END_DT TOM 1 31/08/2009 31/12/2009 TOM 1 01/01/2010 31/12/2010 TOM 1 01/01/2011 23/03/2011 DOCK 2 01/01/2004 31/12/2004 DOCK 2 01/01/2005 31/12/2005 DOCK 2 01/01/2006 31/12/2006 DOCK 2 01/01/2007 31/12/2007 DOCK 2 01/01/2008 31/12/2008 DOCK 2 01/01/2009 31/12/2009 DOCK 2 01/01/2010 31/05/2010 HARRY 3 28/02/2007 31/12/2007 HARRY 3 01/01/2008 31/12/2008 HARRY 3 01/01/2009 31/12/2009
Published by: AChatterjee on April 30, 2012 07:14
Published by: AChatterjee on April 30, 2012 07:14Or like this...
SQL> ed Wrote file afiedt.buf 1 with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all 2 select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all 3 select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual) 4 -- 5 -- end of test data 6 -- 7 select name, cust_id, svc_st_dt, svc_end_dt 8 from ( 9 select name 10 ,cust_id 11 ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt 12 ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt 13 from t 14 cross join (select rownum-1 as yr 15 from dual 16 connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t) 17 ) 18 ) 19 where svc_st_dt <= svc_end_dt 20* order by 2, 3 SQL> / NAME CUST_ID SVC_ST_DT SVC_END_DT ----- ---------- -------------------- -------------------- TOM 1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00 TOM 1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00 TOM 1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00 DOCK 2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00 DOCK 2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00 DOCK 2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00 DOCK 2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00 DOCK 2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00 DOCK 2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00 DOCK 2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00 HARRY 3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00 HARRY 3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00 HARRY 3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00 13 rows selected.
-
Need help to create a search form that returns all values on this line
Hello
I have a pdf document that lists every zip code unique to the USA and for each line, it has five columns of information for each zip. Using the integrated search, when the user key a zip code, the cursor jumps to that page and highlights only the postal code, making it difficult to read the other five columns.
Not sure if this is possible, but it would be the ideal solution:
Enter the postal Code: [search] _ <-user key a zip code if found, return all columns in the same row in the report below
Group: ___________
Description of the Group: _
Mkt Area ____________
City ____________
State ___
This can be done (in the PDF file), but it requires a script to measure.
The worksheet data should be converted to a crude and attached text to the PDF file, and then the script could read and fill in the fields on this basis.
If you are interested in hiring someone to develop this script for you, feel free to contact me privately at try6767 at gmail.com
-
need help to write a conditional query recordset
I have two fields or not in the database. VeteranMarker and VeteranNoMarker. Answering one can be Y or N.
I want to write a statement for my detail page where there is a label "veteran? If VeteranMarker or VeteranNoMarker has a Y in the database, then I want to display "YES" next to the label of "veteran? If neither has a Y, then I want to say 'NO '.
The recordset is called DetailRS1, the fields would be so (I think) DetailRS1.VeteranMarker and DetailRS1.VeteranNoMarker.
I have no idea how to write a conditional statement to achieve this.
Thanks in advance,
MiriamI think I have it solved. Here is the code, and it seems to work. If this is correct, I hope it can help someone else too.
-
Need help to write to Oracle and SQL Server in the Oracle triggering
We have a third which feeds data for us. Their client application feeds directly to some source tables in our Oracle database 10g. We have triggers on those tables that sort and treat lines as they come.
We have a new operation and try to write some of these incoming data now to a SQL Server database through heterogeneous services - essentially the same exact data in two databases. I have a related database that works very well for the selection, but I've never tried to write Oracle PL/SQL to write in a DB SQL Server 2008. My first attempt was met with the following error: "ORA-02047: impossible to join the current distributed transaction.
I found another thread where they say that the only way to do it is by using a stand-alone transaction, but they do not give an example. Here is the section of relaxation that I use:
Can someone point me to a way to accomplish this simple insertion?select to_char(new_date,'MM-DD-YYYY') into sql_txt from dual; insert into mancamp_location@sqlweb ("UnitID", "ManCampID", "Lat", "Long", "UpdateDT", "VehSpeed", "VehDirection", "Landmark") values (v_truck, f_unit, f_lat, f_long, sql_txt, f_spd, f_dir, f_ldmk);
An example of a standalone trigger is:
Suppose you have a table in Oracle:
CREATE TABLE emp_sal
(
EMPNO NUMBER 4,
SAL NUMBER (7.2));and a similar table in a SQL server:
SQL Server:CREATE TABLE emp_sal
(
EMPNO NUMERIC (4).
SAL NUMERIC (7.2));Then, you can create an insert trigger that replicates the data:
CREATE OR REPLACE TRIGGER dg4odbc_repl AFTER INSERT ON emp_sal
FOR EACH LINE
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB '.
VALUES (: new.empno,: new.sal);
COMMIT;
END;
/-Note the validation, otherwise risk of ORA-6519
When you now insert a record into the Oracle database:
insert into emp_sal values (1234, '1200,89');
the trigger is activated and inserts the record in SQL Server:
Select * from 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB;
EMPNO, SAL
----- -------
1234 1200.89It works fine when you post data insert, but as soon as restore you the insert only data Oracle will be cancelled - data will remain as long as the independent transaction dedicated to its SQL Server insert:
insert into emp_sal values (1384, '1200,89');
Rollback;
Select * from emp_sal;
EMPNO, SAL
----- -------
1234 1200.89Select * from 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB;
EMPNO, SAL
----- -------
1234 1200.89
1384 1200.89So I strongly recommend to use the DG4MSQL gateway which is able to participate in distributed transactions and allows validation/restore transactions.
DG4ODBC lie on OTN (http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html-online check out the "See all" link for your favorite platform), cloud of delivery of software Oracle (https://edelivery.oracle.com/) or "My Oracle Support". My Oracle support welcomes the latest version 11.2.0.3. In My Oracle Support goto patches and updates, then search for 11.2.0.3 data set Patch 10404530patch: 11.2.0.3.0 PATCH SET for ORACLE database SERVER, choose your preferred platform and see the Readme which CD contains the gateway software.
Published by: kgronau on April 24, 2012 08:44
-
Query that returns only certain fields in Java
Currently I use a filter that identifies certain keys, then get all the keys and get a unique value of each object. The rest of the object is important enough. I've seen references to the passage on the ability to do it, using CohQL, but I can't run Java.
Basically, I want to do: "select the"Cache"box where key ="asdf '" I just want back the specific 'field' rather than the entire object. How can I do this?
Thank you.Hi user13279246,
You can do this by using the ReducerAggregator. Your code would look like:
Filter filter = QueryHelper.createFilter(...); ValueExtractor extractor = new ReflectionExtractor("isReadOnly"); Map mapResult = cache.aggregate(filter, new ReducerAggregator(extractor));
The mapResult will be indexed by the actual cache keys, but the values will be extracted Boolean property.
If you need to return a number of "columns", you would use the MultiExtractor instead. In this case, each value in the returned map would be a list of corresponding extracted properties.
Kind regards
GenePublished by: ggleyzer on February 15, 2011 16:41
-
Query that count only the column null lines
create table test
(a varchar2 (10))
b varchar2 (10),
c varchar2 (10),
d varchar2 (10),
e varchar2 (10));
SQL > DESC TEST
Name Null? Type
------------------------------- -------- ----
A VARCHAR2 (10)
B VARCHAR2 (10)
C VARCHAR2 (10)
D VARCHAR2 (10)
E VARCHAR2 (10)
SQL > SELECT * FROM TEST;
A B C D E
---------- ---------- ---------- ---------- ----------
A1 - A3 A4-
B1 - B3, B4-
C1 - C3 C4-
D1 - D4 D5
-E2 - E4 E5
I want an application that only count the rows of the column as null
A B C D E
--- ---- ----- ------ -------
1 4 2 0 3
Published by: Nilesh hole, Pune, India, on August 28, 2009 12:30select SUM(case when a is null then 1 else 0 end) ,SUM(case when b is null then 1 else 0 end) ,SUM(case when c is null then 1 else 0 end) ,SUM(case when d is null then 1 else 0 end) ,SUM(case when e is null then 1 else 0 end) from TEST /
Published by: Toon Koppelaars August 28, 2009 09:07
-
I need help to write a script that detects the first instance of a paragraph style and then change
I need help to write a script that detects the first instance of a paragraph style and then he goes to a different paragraph style. I don't necessarily need someone to write all this, by the biggest problem is to find how to find just the first instance of the paragraph style. Any help would be greatly appreciated, thank you!
Hello
then try this with your active doc:
....................
myDoc var = app.activeDocument;
mStyle var = myDoc.paragraphStyles.item ("PS_NameToFind"); change the name to paraStyle
var mStyle_1 = myDoc.paragraphStyles.item ("PS_NameToChange"); change the name to paraStyle
var mFrames = myDoc.pages.everyItem ().textFrames.everyItem () .getElements ();
app.findTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = mStyle;
for (var k = 0; k)< mframes.length;="">
{
currFound = mFrames [k] .findText ();
If (currFound.length > 0)
currFound [0] .paragraphs [0] .appliedParagraphStyle = mStyle_1;
}
app.findTextPreferences = null;
................
Rgds
-
I need a query that returns the average amount of characters from text colum in MS SQL.
I need a query that returns the average amount of characters from text colum in MS SQL.
Could someone show me how?Sorting, I need of the
DATALENGTH
function
-
How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?
I have only:D: / images (where are necessary + not need files)-a list with only the necessary files-a list with new names for the files neededThank you.Hi Pustiu,
Thanks for posting in the Microsoft Community.
You want to know how to select the files in a folder using a list with the files you want and after that rename only the files using another list with desired new names.
I would have you post your query in the TechNet forums because it caters to an audience of it professionals.
Your query will be better addressed there.
Check out the link-
http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/threads
We know if you need help. We will be happy to help you. We, at tender Microsoft to excellence.
Thank you.
-
Query that returns number 1 - Add additional columns based on percentages
I have a query that returns a large number. The return value will always be a single field (a column, a line, a single value).
I need to have also three other columns in the return of this request: one that returns a number that is 50% of the original number, one that returns a number that is 75% of the original number, and one that is double the original number. How is that possible? If anyone can point me to examples, it would be a great help. I got the results mixed by searching, so I'm not sure good practices.
Thank you for the input in advance.
Hello
Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.
Explain, using specific examples, how you get these results from these data.
If you show what you want to do using commonly available tables, like those of the scott schema, then you don't need to display the sample data; just results and explanations.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
I'm not sure that understand the question.
If x is a number, then
.50 * x is 50% of this number,
.75 * x is 75% of that number, and
2 * x is to double this figure.
You can get them all in the same query, if you want to. For example:
SELECT ename
sal
.50 * sal AS p_50
.75 * sal AS p_75
2 * sal AS dbl
FROM scott.emp;
Output:
ENAME SAL P_50 P_75 DBL
---------- ---------- ---------- ---------- ----------
SMITH, 800, 400, 600, 1600
1600 800 1200 3200 ALLEN
1250 625 WARD 937,5 2500
JONES 2975 1487.5 2231,25 5950
1250 625 MARTIN 937,5 2500
2850 1425 BLAKE 2137,5 5700
2450 1225 CLARK 1837,5 4900
3000 1500 2250 6000 SCOTT
KING 5000 2500 3750 10000
1500 750 1125 3000 TURNER
1100 550 825 2200 ADAMS
JAMES 950 475 712,5 1900
FORD 3000 1500 2250 6000
1300 650 975 2600 MILLER
Is that what you ask?
-
NEED HELP WITH SERVICE PACK 3. After downloading and the computer goes into rebooting mode I get the screen to restart with three options, network security safe mode and the other thing. , but it of although he gets, he keeps countdown to restart and reboots and restarts, over and over again, never reboots, same screen. my computer won't let me out this screen even after I turned off the computer and turn it back on, I get the same screen. the only way I can get out of this is to erase my computer everything and bring it back to factory, right out of the box, this big headaches. Thanks for anyone who can help me. PS. Keep the answers in simple terms please.
Hi BSRC$, in stock
- You have security software installed on the computer?
- You receive an error message when you restart the computer?
Reinstalling Windows XP to the factory setting would not be the first option.
It is possible that some third-party programs or the services installed on the computer interfere with the installation of service pack 3.
I suggest that you try to uninstall service pack 3 from the computer by using the recovery console and subsequently ask the article below for what to do before installing the service pack 3on the computer.
How to remove Windows XP Service Pack 3 from your computer
http://support.Microsoft.com/kb/950249
Steps to take before you install Windows XP Service Pack 3
-
I need help to cancel my account creative cloud I wrote the wrong email address when I created it
I need help to cancel my account creative cloud I wrote the wrong email address when I created it. Is there a way I can do?
Hello
Please contact support by calling/chat for cancellation requests and billing queries:
* Be sure to stay connected with your Adobe ID before accessing the link above *.
You can also check the help below document:
https://helpx.Adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html
Please go through the Adobe - General conditions of subscription as well.
-
I need help to reinstall photoshop. I don't have the original disc. How can I reinstall the PS?
What version of the full scale of the PS do you need?
Nancy O.
Maybe you are looking for
-
Why isn't everything: cache show me anything in my cache more?
I have the habit of using the add-on Cache Viewer, but that has stopped working. I tried to use the Cache Viewer2 add-on, but that no longer works.
-
LV TEN F5 SP1 does not appear in the components for deployment...
Hello Just migrated my x 32 to x 64 TS2014 TS2013 LV2013 & apron & LV 2013 x 64. I'm now trying to build a new installer for deployment for my test stations, but LV RTE SP1 F5 does not appear in the components for deployment, even if it is properly u
-
Is there anyway to change the Xp pro from Spanish language to English 100%?
Basically I have a Spanish version of Xp installed on my computer. I want to update so that everything is in English of the screen starting and all that comes after. Instead of say Bienvenido when it starts, I want to say welcome I want to say change
-
Failed to retrieve Windows 8 HP (recovery discs) used
Hello. I don't know where to start. System Info- HP Pavilion Notebook g6t-2200 Windows 8 (64-bit) It comes to my sisters computer. His system was slow, so I had to reinstall the OS using the recovery media that I ordered for the system. Ive reinstall
-
Cannot install microsoft visual c ++ runtime of the 2015
HelloI can't install microsoft visual c ++ runtime 2015, during the attempt he stucks at 100% for hours. I have to manually cancel.I have tryied uninstalling all previous microsoft visual c ++ runtimes, does not help... It is Windows 7 N (for student