Here he comes to confuse his day! (should be my handle from now on)
Im confused and very much lost.
I need to figure out how to make a select statement for getting FriendID to relate to there UserID


As you can see FriendID relates to the UserID of my User table, so if FriendID = 2 then display UserID 2 details.
What im trying to do is if im UserID 1 I want to display all my friends, my userid is set by a session,
What I need to do is find out who my friends are so Select FriendID from freinds where SessionID = UserID then some how figure out who friendsID belongs to in the User table and display his firstname, secondname and his picturepath.
Very confusing...
My table structure looks like this:
So to sum it up what I need in my select command:
To find out who im friends with (currentsession UserID has FriendID's) Display FirstName, SecondName, picturepath of friendID related to his own UserID
Example:
I (userID=1) have FriendID 2 = UserID 2 so select firstname, secondname from User where UserID=2
I could have relational problems with my table structure tho not sure.
I hope u can understand my confusion:
EDIT for those that cant see the images of my db
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE SCHEMA IF NOT EXISTS `gymwebsite2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `gymwebsite2` ;
-- -----------------------------------------------------
-- Table `gymwebsite2`.`User`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gymwebsite2`.`User` (
`UserID` INT NOT NULL AUTO_INCREMENT ,
`Email` VARCHAR(245) NULL ,
`FirstName` VARCHAR(45) NULL ,
`SecondName` VARCHAR(45) NULL ,
`DOB` VARCHAR(45) NULL ,
`Location` VARCHAR(45) NULL ,
`Aboutme` VARCHAR(1045) NULL ,
`username` VARCHAR(45) NULL ,
`password` VARCHAR(45) NULL ,
PRIMARY KEY (`UserID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `gymwebsite2`.`WallPosting`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gymwebsite2`.`WallPosting` (
`idWallPosting` INT NOT NULL AUTO_INCREMENT ,
`UserID` INT NOT NULL ,
`Wallpostings` VARCHAR(2045) NULL ,
PRIMARY KEY (`idWallPosting`) ,
INDEX `fk_WallPosting_User` (`UserID` ASC) ,
CONSTRAINT `fk_WallPosting_User`
FOREIGN KEY (`UserID` )
REFERENCES `gymwebsite2`.`User` (`UserID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `gymwebsite2`.`Pictures`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gymwebsite2`.`Pictures` (
`idPictures` INT NOT NULL AUTO_INCREMENT ,
`UserID` INT NOT NULL ,
`picturepath` VARCHAR(1045) NULL ,
PRIMARY KEY (`idPictures`) ,
INDEX `fk_Pictures_User1` (`UserID` ASC) ,
CONSTRAINT `fk_Pictures_User1`
FOREIGN KEY (`UserID` )
REFERENCES `gymwebsite2`.`User` (`UserID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `gymwebsite2`.`Friends`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gymwebsite2`.`Friends` (
`idFriends` INT NOT NULL AUTO_INCREMENT ,
`UserID` INT NOT NULL ,
`FriendID` INT NOT NULL ,
PRIMARY KEY (`idFriends`) ,
INDEX `fk_Friends_User2` (`FriendID` ASC) ,
INDEX `fk_Friends_User1` (`UserID` ASC) ,
UNIQUE INDEX `FriendID_UNIQUE` (`FriendID` ASC) ,
CONSTRAINT `fk_Friends_User2`
FOREIGN KEY (`FriendID` )
REFERENCES `gymwebsite2`.`User` (`UserID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Friends_User1`
FOREIGN KEY (`UserID` )
REFERENCES `gymwebsite2`.`User` (`UserID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;