Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to compare ssn with four tables to find any unmatched ssn. i need assistance with sql query. thanks in advance
Based on the information provided, the basic concept would be:
SELECT *
FROM yourTable
WHERE
ssn NOT IN (
SELECT ssn
FROM ssnTable1
)
AND
ssn NOT IN (
SELECT ssn
FROM ssnTable2
)
AND
ssn NOT IN (
SELECT ssn
FROM ssnTable3
)
AND
ssn NOT IN (
SELECT ssn
FROM ssnTable4
)
If the ssn should exist in all four tables at once, then replace the above ANDs with ORs.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
SELECT DISTINCT CITY FROM STATION WHERE MOD(ID,2)=0 ORDER BY CITY ASC;
SELECT DISTINCT CITY FROM STATION
Primary command to select data from the database. It is asking to select CITY from the table STATION whose data is unique. Thus, no duplicates are produced in result.
WHERE MOD(ID, 2) = 0
Only select those that have an even number ID.
ORDER BY CITY
Sort the results with respect to CITY names.
ASC
Sort in ascending order; which means that cities with names starting with A will come before those that have Z as first letter.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a table name customers with two columns, case id and owner. I need to write a query to select random 5 caseids for every name in owner column.please help
For a start, you need something like:
SELECT TOP 5
ID,
[Case ID],
[Owner],
Rnd(-Timer()*[ID]) AS RandomRecord
FROM
[Cases]
ORDER BY
Rnd(-Timer()*[ID]);
to be used as a subquery filtered on OwnerID of your Owners' table.
I once posted an article on this with a lot more details:
Random Rows in Microsoft Access
You can use in:
select t.*
from t
where t.id in (select top 5 id
from t as t2
where t2.name = t.name
order by Rnd(-Timer()*[ID])
);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How can I put 1,2,3,4.... in sequence order in column salary where salary is null?? in oracle
I tried many things but could not find any accurate result
select nvl(column,1) as columnName from yourTable
Use ROWNUM pseudocolumn with nvl function:
select nvl(salary, ROWNUM ) from yourTable
ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
SELECT staffNO, name, surname, position
FROM Staff s, Branch b
WHERE s.branchNo = b.branchNo AND city = 'London';
I have tried to make the above SQL code into a sub-query and I'm not getting anywhere. Im a beginner in SQL, how do I go about it?
The equivalent query with a sub-query and IN clause would look like this:
SELECT staffNO, name, surname, position
FROM Staff s
WHERE s.branchNo IN (
SELECT b.branchNo
FROM Branch b
WHERE b.city = 'London'
);
This of course assumes that staffNO, name, surname, position are all available as fields on the Staff table. If any of those fields come from Branch then you do need to use the JOIN syntax instead.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
have a table EMP having two columns ID, Name
EMP contains lots of entries, obviously, repeated entries.
I need to print those entries which are being repeated, but, i don't have to look on NAME column, on the basis of id only i want to print the repeated entries.
Please help me out. Thanks in advance.
To display all the repeated ids:
SELECT ID
FROM EMP
GROUP BY ID
HAVING COUNT(*) > 1
To also print the names:
SELECT ID, NAME
FROM EMP
WHERE ID IN
(
SELECT ID
FROM EMP
GROUP BY ID
HAVING COUNT(*) > 1
)