Mysql, retrieve students who haven't received a request from me [closed] - mysql

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 am currently logged in as the first student. I want to retrieve a list of the students I did not send a request to yet. I also want to retrieve a list of students I sent a request to.
Both sender_id and Rec_id are foreign keys referencing to Students.id.
DB schema

Hi Souleiman and welcome to stackoverflow! Your question is not quite clear, you say that sender_id and Rec_id in requestts are both referencing to students, but you can't see to which field exactly. Your requestts table contains different entries in these fields.
Next time you should post the output of SHOW CREATE TABLE students and SHOW CREATE TABLE requestts and a little INSERT statement for the data. Furthermore it would be nice if you would explain the relations and show what you have already tried (see Barmars comment).
I suppose that the relevant foreign key in requestts is Rec_id, so you could try this query:
SELECT s.email FROM students s WHERE s.id NOT IN
(SELECT Rec_id FROM requestts WHERE Rec_id = s.id);
Hope this helps. Have fun learning SQL!

Related

Joining tables that don't have a common id [closed]

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 2 years ago.
Improve this question
I have two tables in a MySQL database. One is "accounts" and one is "posts". I'm at the point where I want to allow users to only edit their posts, which I think means I need to create a table join. The problem is there isn't a common id for each table.
Accounts:
id, first_name, last_name, username, password, email, activation_code, rememberme, role
Posts:
id, title, body, author, tags, status, image, created_at
I'm still searching on how to do this. I know I need to create a common id. That's where I'm getting confused since there will need to be a common link when a post is created. Can someone point me in the right direction for making this happen please?
The "author" column in Posts table should ideally be a foreign key of the "id" column in Accounts table. This would allow you to join the tables based on this column. A foreign key can be added as follows for your case -
ALTER TABLE Posts ADD FOREIGN KEY (author) REFERENCES Accounts(id);
You can have a look at a tutorial about foreign keys here - https://www.w3schools.com/sql/sql_foreignkey.asp

MySQL user data storage [closed]

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 years ago.
Improve this question
I have two tables that should somehow be associated. Let's call them table_a and
table_b. A row in table_a can be associated with multiple rows in table_b, and the same goes the other way around. How could I achieve this? Should I use a pivot table?
Both tables have an auto-incrementing id-column.
What you're looking for is called a many-to-many relationship (a given user has zero or more games, a given game has zero or more users). This is typically handled with a "mapping table", e.g. USER_GAMES which has a user_id and a game_id, uniqueness is on the combination of these. http://www.joinfu.com/2005/12/managing-many-to-many-relationships-in-mysql-part-1/ has some good details.
As it is a many to many relationship, an intersection table with the user ID & game ID would be the best. Otherwise you would have to parse the list of game ID's stored in the user table and that would cause performance issues.

How to retrieve userID from table [closed]

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 years ago.
Improve this question
I have a table named 'User' and it has an autoincremented field userID.
I want to retrieve that userID in my servlet. There is no such parameter/field referred to on that respective HTML. How can I use that userID in my servlet?
I would say your question is far to broad for a definite answer mate but here goes my best guess.
I assume you run this table and data in mysql since you tagged this as mysql.
you can retrieve the data you wish with the query as below:
SELECT userID FROM User;
Note: If you have more than 1 this will return all of them. If you want to limit this down to 1 you will need to match that to another unique parameter in your table. For example lets say you have a column in User table called "telephone"
the query would be:
SELECT userID FROM User WHERE telephone = '1234567890';
You can then display the result in your html, depending on what language you use to execute this query with.
Hope this helps

Database Design daily data [closed]

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 years ago.
Improve this question
I have a question about database design, I'm wondering how do you go about saving daily user data.
For example I have a table called Accounts
structure is accountID, accountName, DailyScore, WinRate
how can I keep track of DailyScore and WinRate for each day. Do I keep creating tables named after a date or is there a better way.
Accounts has info about each "account" -- account_id, name, etc. This table is rather static -- you occasionally add a row, and sometimes change something.
Scores has new rows every day -- account_id, date, score, etc. The PRIMARY KEY would have two columns: account_id and date.
Not knowing how winRate is calculated, it is unclear where, if anywhere, it should be stored. Is it calculated from the scores??

How to tie (connect) to values in mysql? [closed]

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
I am newbie in programming and I need some help.
I have table (clubs) in DB with teams names and their id.
Next I want to create match in table "matches" in new table named "matches".
How can I tie team's id from "clubs" with teams (home&away)in table matches. I need that id in next actions.
I thought about foreing key, but I cant us it.
Thanks in advance for ur help
Regardless of if the two tables are linked via. a foreign key relationship (although it is good practice to do so) when selecting you can still use a JOIN to connect the two tables. Since you have both a home and away team you need to join the clubs table twice, once for each team.
SELECT m.*, ch.name AS homeClub
FROM matches m
INNER JOIN clubs ch
ON ch.id = matches.home_id
This query will get the match and the home club name, I leave it to you to figure out how to get the away club's name.
Read http://dev.mysql.com/doc/refman/5.0/en/join.html for more information on using joins.