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
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:
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 answers here:
MYSQL Left Join how do I select NULL values?
(4 answers)
Closed 4 years ago.
I'm developing a system and creating invoices. I want the record where no invoice has been created.
I'm trying to write a MySQL query, where I need the records whch can not be joined with another table. In other words, the records that do not have a linked record in the other table.
I tried the following query
SELECT exports.id as e_id,export_invoices.id as i_id
FROM exports
LEFT JOIN export_invoices ON export_invoices.export_id = exports.id
and got this result:
Which gives all value and also the record of which invoice is not created with NULL value (I want to have that [e_id->2 from result]). I just want to extract that null value record's master id.
Simply add the where condition in your query -
SELECT exports.id as e_id,export_invoices.id as i_id
FROM exports LEFT JOIN export_invoices on export_invoices.export_id = exports.id
WHERE export_invoices.id IS NULL;
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 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