I am new with the MS access SQL and the following is what I would like to do
in my database table
I have the following data
basically no duplicate, I tried "Distinct" but given my result is not one column only so I can't do that. I research online and look like it might need to use inner join but I only have one table only.
Appreciate if anyone can help me up..
Thanks
Regards,
Marc
You should be able to run the following query:
SELECT DISTINCT name, birthday
FROM [table];
select DISTINCT column1, column2, ...
from TABLENAME;
Replace columns and table name with respective values.
like this
select DISTINCT name, birthday from TABLENAME;
Related
I am attempting to combine a rows based on the customer id and a T/F column. I am new to coding and SQL and I've tried 'GROUP BY' in my query that has 50 plus columns but i am unable to do so.
Data Set:
Desired Result
Thank you in advance.
There are probably more elegant solutions, but try the following...
select recordID, city, max(ispaid)
from dat
group by recordID, city
Here's a link to SQL Fiddle where you can play with it.
You can use distinct
select
distinct recordId,
city,
isPaid
from yourTable
this might sound kind of strange, but what I want to do is this:
SQLite table # SQL Fiddle
I want as result:
peter
when I query ID<=5
and
alvinpeter
if ID is <=10 (names added to one in alphabetical order)
Anyone know how to do this with SQLite only?
Thanks in advance, best regards!
Following will do:
SELECT GROUP_CONCAT(name,'')
FROM (
SELECT DISTINCT name
FROM testtable
WHERE ID<=10
ORDER BY name
);
(in SQL Fiddle)
I need to reorder my query to have the name in the first column, but I still need the rest of the columns populated as well.
How would you implement an alias in oracle to achieve this query?
select s.name, s.* from table as s
Thanks for the help.
There is no simple way around this, you must specify all columns in the order you would like them.
select s.name, s.column1, s.column2, ... from table as s
i did a few searches and i saw a few people try to do some kind of nested select statement in order to fix the issue. i did not understand it.
can someone help me please:
the data is already sorted by provider name, each provider name is listed more than once based on various other columns in the table. however, when i do this, i do not get one line per provider name. instead the provider names repeat as if i am not using group by
here is the code:
create table moopnjsummary2 as
select mnj.ProviderName
from moopnj mnj
group by mnj.ProviderName
Do you want a list of mnj.ProviderName without repeats? What is your final goal?
You could also try SELECT DISTINCT
select mnj.ProviderName, count(*) as Providernamecount
from moopnj mnj
group by mnj.ProviderName
If all you're looking for is distinct ProviderNames, try running
SELECT DISTINCT moopnj.ProviderName FROM moopnj
This is a not a full answer to your question but if all you want is a list of provider names you should use: "Select DISTINCT mnj.ProviderName ...". That will eliminiate all duplicates.
I've two tables which have following columns:
Now I want have a SQL query which gives me an output as follows:
I wrote already some SQL code, but this doesn't work because the union operator needs the same number of columns with the same type. Have a look.
SELECT *
FROM
(SELECT User_tbl1.Username, User_tbl1.Surname, User_tbl1.Givename
FROM User_tbl1
UNION
SELECT User_tbl2.User_PK
FROM User_tbl2)
Can someone help me to bring my SQL query working, so that it will output a hyphen at surname and givename if the record is located in table "User_tbl2"?
Thanks a lot!
As simple as:
SELECT User_tbl1.Username, User_tbl1.Surname, User_tbl1.Givename
FROM User_tbl1
UNION
SELECT User_tbl2.User_PK, '-', '-'
FROM User_tbl2