This question already has an answer here:
How do I compare two columns in SQL?
(1 answer)
Closed 9 years ago.
I know I just asked a question, but I realized I asked it all wrong
So in MYSQL if you I a two tables one with an SSN column and another with a CSSN column, both integers, how can I determine which SSN's are NOT in the CSSN column?
This simple query should do it:
select SSN from table1 where
SSN not in (select CSSN from table2)
Here's a SQL Fiddle: http://sqlfiddle.com/#!2/d89f7/1
You can try this.
SELECT * FROM tab1 t1 INNER JOIN tab2 t2
ON t1.SSN <> t2.CSSN
Related
This question already has answers here:
SQL IN Clause - get back IN elements that did not match
(5 answers)
Closed 7 months ago.
I have a random input of identifiers (primary key), and I need to return the identifiers which were not found in the mySql table.
Lets say my identifier list is ['FEB221571','1221SC170','75960620447200111', 'ABC12344'].
My table has the first three identifiers so I can find them on the table but I wish the last one to be returned as it cannot be found in the table. How do I implement that?
select * from identifier_list a
where not exists (select 'x' from some_table b and a.id = b.id);
This question already has answers here:
mysql opposite of inner join
(3 answers)
Closed 2 years ago.
is there a query where I can compare 2 table datas? For example.
My first table has ID 1,2,3,4,5,6,7,8,9,10. My 2nd table has ID 1,3,5,7,9.
My target is to get the missing values. So my expected output is 2,4,6,8,10.
Thank you in advance
Try this:
SELECT
num
FROM
first_table t1
WHERE
num
NOT IN
(SELECT
num
FROM
second_table
);
This question already has answers here:
Data from two tables with same column names
(4 answers)
MySQL - Selecting data from multiple tables all with same structure but different data
(6 answers)
Closed 2 years ago.
I have this problem, which it's keeping me out of focus from the main project on Laravel.
I have 2 tables without any fk on them
TableA:
id(INT)
Name(VARCHAR)
EventId(INT)
PlayerChoiceId(INT)
and
TableB:
id(INT)
PlayerChoice(VARCHAR)
PlayerColor(VARCHAR)
I need to make a method on my controller to select all of the data from TableA with the PlayerChoice value, not the id from TableB, but without LEFT JOIN.
Example:
id(TableA)|Name|EventId|PlayerChoice
Something like:
SELECT a.*, b.PlayerChoice from TableA a, TableB b where a.PlayerChoiceId = b.id;
Will give you:
a.id a.Name a.EventId a.PlayerChoiceId b.PlayerChoice
is that what you're looking for?
This question already has an answer here:
MySQL JOIN tables with duplicate column names
(1 answer)
Closed 6 years ago.
I am using SELECT SQL_CALC_FOUND_ROWS *, but I need to left join a table that has a column with the same name as the first one.
$sql = "
SELECT SQL_CALC_FOUND_ROWS *
FROM {$this->_db}
LEFT JOIN $this->_db2 ON $this->_db2.calc_id = $this->_db.calc_id
";
Any idea how to make this work, as now the value from the 2nd table is overwriting the fist one?
Since you are joining a table with a field with the same name as another, you cannot use SELECT *.
You need to manually list the fields that you want in the SELECT statement.
This question already has answers here:
selecting distinct pairs of values in SQL
(3 answers)
Closed 6 years ago.
I have a table with related values. Sometimes there are records with the reverse relation. I want to delete those but dont know how to handle this. eg:
table with two columns (KOL1 & KOL2):
A-B
A-C
A-D
A-E
B-C
B-E
F-G
C-A
C-D
In the example above C-A is the record I want deleted because it is the reverse record of A-C already in the list.
How can I do this using access QUERIES?
ok,I think this does the job
SELECT E1, E2
FROM Table1
WHERE E1<=E2
UNION
SELECT E2, E1
FROM Table1
WHERE E1>E2