Selecting all uppercased-value rows of a table in SQL Navigator - sql

I have a table with an email address column. Some email addresses in the table contain uppercase letters. I would like to fetch all the rows with uppercase emails (in order to set them to lowercase). How do I select all the rows where the email address contains uppercase letters?

I believe Oracle is case sensitive by default? If so, then this should work:
SELECT *
FROM table_name
WHERE LOWER(email) <> email
If this works then you can simply update them with
UPDATE table_name
SET email = LOWER(email)
WHERE LOWER(email) <> email

Related

Select Records with same email in different columns

I want to extract all records that has same email in different fields from an email table. I am not sure how to do that in sql. looking for help.The image has id and email fields. I am trying to extract records which has same email in different fields.
If I understand your question correctly, you need to compare each email address in a row with every other email address in the same row, taking into account that you don't want to have empty email addresses compare equal. Here's my suggestion (which I've played around with a bit here):
select * from email
where
(email1 <> '' and email1 in (email2, email3, Add1, Add2))
or (email2 <> '' and email2 in (email3, Add1, Add2))
or (email3 <> '' and email3 in (Add1, Add2))
or (Add1 <> '' and Add1 = Add2)
Additional note: If you have superfluous spaces tagged on to any emails, you may need to trim them all.

delete a line beginning with N characters SQL Postgres

I have 2 tables SQL:
USER with columns ->: uid, name, mail
Phone ->: id, brand, model, refFirtUser
refFirtUser is a column that constitutes the user's id - and a random number
example : refFirtUser (uid_users-12345687) -> 9145-12345687
i want to delete in table "Phone" all data .
I must to get "uid" of user by mail and to search N first characters before "-".
all data in column "refFirtUser " starting with "uid-xxxxx"
(where uid is the id of the user).
the only data I have is email
How should I do?
If you want to delete the from phone the user with mail 'someone#gmail.com':
delete from phone
where
refFirtUser like (select uid from user where mail = 'someone#gmail.com') || '-%'
It is ambiguous from your explanation whether user.uid is the number before - or after. In either case, you may use exists
delete from phone p
where exists ( select 1 from user u where mail in ( 'listofmail')
and p.refFirtUser like '%-'||u.id );
OR
delete from phone p
where exists ( select 1 from user u where mail in ( 'listofmail')
and p.refFirtUser like u.id||'-%' );

Trying to write a SQL expression that drops a collection of rows

I've indexed my email inbox and have a table of email_addresses, thread_id, subject, to, from...etc
I would like to "group" (but group by doesn't work) the rows by email address, and then eliminate that collection of rows if any row inside that collection contains a certain email address inside the to field.
I've tried:
select *
from emails
where emails.[to] != "test#email_address.com"
But that just eliminates individual rows, and not the collection of rows that share an email address.
Unfortunately using group by loses all information beyond the top level row and the database no longer can check to see if there are other rows with that email address in the to field.
Any thoughts?
You need a group by on email_address and a conditional check for any of the to email specified.
select email_address
from emails
group by email_address
having count(case when emails.[to] = 'test#email_address.com' then 1 end) = 0
If you need the entire row information for such email_addresses use
select * from emails where email_address in (
select email_address
from emails
group by email_address
having count(case when emails.[to] = 'test#email_address.com' then 1 end) = 0)

select to check if a column does not contain a value in a provided array

I would like to select to check if any of the countries I have in my string array is not contained in the country table in the psql database.
Therefore I have a list of country names ARRAY['Country1','country2'.....]
and I have a table of country and I want a query to select countries that are not in this string that I will provide to the where clause
Something like this
SELECT name from country where name not in (ARRAY['Country1','country2'.....])
You were nearly there:
SELECT name
from country
where name <> ALL (ARRAY['Country1','country2'.....])

SQL command to clear specific text

Trying to run a SQL command that reads * from my database but I need it to seek specific text in the email field and return a null if it doesn't equal. Example, I'm trying to filter out all emails in our database that are not internal email addresses, so it would need to filter out any that don't have our company name in it.
I was able to filter this with a LIKE command, but it just simply ignores the rest of the fields in the results. I know access has the IIf(InStr command, so I'm hoping there is something similar in SQL
Not sure I fully understand, but something like this may work for you.
USE Server
SELECT
firstName AS EmployeeFirstname
, lastName AS EmployeeLastname
, title AS EmployeeTitle
, id AS EmployeeID
,
Case
When emailAddress Like '%#mycompany.com'
Then emailAddress
Else Null
End AS EmployeeEmailAddress
FROM db.Information
WHERE ISNUMERIC(id)<> 0
AND empStatus = 'A'
So what this will do is give you the rows regardless of what email they have (still taking into account your other selections of ISNUMERIC(id)<> 0 AND empStatus = 'A'). But in those rows, if the email is your company they would display and if not the field would be Null. Obviously change the “mycompany.com” it the Like to whatever string you actually need to search for,
If you want to exclude all records where the company is not in the email address, add
where
emailAddress not like '%companyname%'
If you want to blank out the non-company email addresses, you can use case
Select
case when emailaddress not like '%company%' then null else emailaddress end