I want to check what hobbies a user has and I want to insert it to a database.
I was thinking about making a column Hobbies and to insert the data in a string type in that form : {"Hobby1", "Hobby2", "Hobby3"}
But then the code to filter out the hobbies would be big, is there a more efficient way?
Create a Hobbies table and insert hobbies into that such as Golf, Photography etc.
Then create a UserHobby table to associate a User with a Hobby such that a User can have multiple hobbies.
EG
UserID FirstName
1 Bob
2 John
HobbyID HobbyName
1 Golf
2 Photography
UserHobbyID UserID HobbyID
1 1 1
2 1 2
3 2 2
Related
How do I track the list of updated columns in a table
Table1
Name Place Email Id
John US john#gmail.com 1
Sam US sam#gmail.com 2
Now if I update Name,place columns for John and place,email for Sam like
Name Place Email Id
Johnny UK john#gmail.com 1
Sam UK sammy#gmail.com 2
I want to store the list of updated attributes in another table as following
Id ListOfModifiedAttributes Status othercolumns
1 name,place success
2 place,email success
How to achieve the above in plsql.
I have a table containing meetings:
MeetID Description
-----------------------------------------------------
1 SQL Workshop
2 Cake Workshop
I have another table containing all participants in the meetings:
PartID MeetID Name Role
-----------------------------------------------------
1 1 Jan Coordinator
2 1 Peter Participant
3 1 Eva Participant
4 1 Michael Coordinator
5 2 Jan Coordinator
6 2 Peter Participant
I want to find is a list of all meetings that have 2 or more participants with Role = 'Coordinator'.
Eg. in the example above that would be the meeting with MeetID=1 and not 2.
I cannot for the life of me figure out how to do this, allthough I think it should be simple :-)
(I am using SQL Server 2012)
This is easy to do using group by and having:
select MeetId
from participants p
where Role = 'Coordinator'
group by MeetId
having count(*) >= 2;
Note: Role is a potential keyword/reserved word, so it is a bad choice for a column name.
I have 2 tables e.g.
First table
ID Value
1 Apple
2 Orange
3 Banana## ...
Second Table
PERSON FRUIT
Amy 1
Peter 2
Charlie 1,2
Dick 2,3
I would like to for example save what fruits the users have in just one column. So that when I call out what Charlie wants, I can somehow receive and output of Apple, Orange; and for Dick - Orange, Banana etc.
I am not really sure where to start on achieving this. Is it possible to do it purely in an SQL select statement alone?
You could implement a link table. For example.. you have a Fruit Table, which stores all the unique fruits, and you have a Person table that stores all unique people.
So you should create a third table that links unique fruits to people for example...
ID FRUIT PERSON
1 1 1
2 1 2
3 2 1
etc... then a select on the link table with the person ID, would bring up all the fruits that person likes.
I have a table to be imported from excel.It has an column called the sector table name "ExcelTable"
Name Title Sector
John manager Sofware
Sam Lawyer Jus
"ExcelTable" has 3284 rows.I create table called "SECTORS"."SECTORS" table's cloumn like this
SectorId SectorName
1 Sofware
2 Jus
It has 61 rows.
I inserted "EXCELTABLE" to "GLOBALCONTACTS".They has same rows number 3284 I want to insert "GLOBAL_CONTACTS" table sector by sectorid .It is now
ContactId Name Title Sector
1 John manager null
2 Sam Lawyer null
I want it to be like this
ContactId Name Title Sector
1 John manager 1
2 Sam Lawyer 2
I think you just want to join ExcelTable to Sectors for an INSERT:
INSERT INTO GLOBAL_CONTACTS (Name,Title,Sector)
SELECT e.Name,e.Title,s.SectorID
FROM ExcelTable e
INNER JOIN Sectors s
ON e.Sector = s.SectorName
Say I have the following table:
App owner owner_id
______________________
1 John NULL
2 Jack 000123
3 John NULL
4 April 000124
5 John NULL
6 April 000124
7 John 000123
8 Ash NULL
9 Ash NULL
10 Ash NULL
If I need to update John and Ash's owner_ids, is there a way to update each owner's owner_id for every occurrence in the table by only entering the information once?
I have to do this for about 1000 owners, but with the amount of duplicates I am looking at around 10000 blank owner_ids.
I do not have the proper rights to restructure or split the table.
If I didn't misunderstand your question, it's just:
update owners_table set owner_id = '000001' where owner = 'john'
update owners_table set owner_id = '000002' where owner = 'ash'
This will set the owner_id to 000001 in every row where the owner is John, and to 000002 in every row where the owner is Ash.
It's just more copy & paste when you have a lot of owners, because you have to create one query for each owner.
Another way would be to create a temporary table with just the owner and his new id:
owner newid
--------------
John 000001
Ash 000002
You can enter hundreds or thousands of owners and their new owner_ids into the table.
Then, you can update them in your main table all at once with the following query:
UPDATE owners_table
INNER JOIN ownertmp ON owners_table .owner = ownertmp.owner
SET owners_table.owner_id = [ownertmp].[newid];
After that, you can delete the temporary table again - it's just needed to run the query.