Connecting DB tables
-
Hey :) Ive tried the INNER, LEFT, RIGHT join but it doesnt seem as if my tables are connecting. I have tables with different names and none match. I also have a main table(login/register) and want the rest to connect to that. How do I go about doing this? Thank ya :)
-
Hey :) Ive tried the INNER, LEFT, RIGHT join but it doesnt seem as if my tables are connecting. I have tables with different names and none match. I also have a main table(login/register) and want the rest to connect to that. How do I go about doing this? Thank ya :)
Post your SQL code and table definitions and you should get some help here.
-
Hey :) Ive tried the INNER, LEFT, RIGHT join but it doesnt seem as if my tables are connecting. I have tables with different names and none match. I also have a main table(login/register) and want the rest to connect to that. How do I go about doing this? Thank ya :)
MekaC wrote:
How do I go about doing this?
There is no way for anyone to tell you without seeing your tables. However, a generic answer is like this.
SELECT table1.*, table2.* -- select everything from table1 and table2
FROM table1
INNER JOIN table2 ON table1.field1 = table2.field1 -- here you put what 2 columns (at least) match the tables.MekaC wrote:
I have tables with different names and none match.
If no tables match then you can't connect them with your login code, but why would you want to anyway? I don't think you are using the right words to expain youself.
-
Hey :) Ive tried the INNER, LEFT, RIGHT join but it doesnt seem as if my tables are connecting. I have tables with different names and none match. I also have a main table(login/register) and want the rest to connect to that. How do I go about doing this? Thank ya :)
Here are my tables :) :
Table structure for table `categories`
CREATE TABLE `categories` (
`id` int(30) NOT NULL,
`name` varchar(250) NOT NULL,
`description` text NOT NULL,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `comments`CREATE TABLE `comments` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL,
`comment` text NOT NULL,
`date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `forum_views`CREATE TABLE `forum_views` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `friendship`CREATE TABLE `friendship` (
`friend_id` int(11) NOT NULL,
`receiver` varchar(30) NOT NULL,
`sender` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `member`CREATE TABLE `member` (
`member_id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `messages`CREATE TABLE `messages` (
`messageid` int(11) NOT NULL,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`message` varchar(5000) NOT NULL,
`date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Table structure for table `myfriends`CREATE TABLE `myfriends` (
`friend_id` int(11) NOT NULL,
`myid` varchar(30) NOT NULL,
`myfriends` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-
Post your SQL code and table definitions and you should get some help here.
-
MekaC wrote:
How do I go about doing this?
There is no way for anyone to tell you without seeing your tables. However, a generic answer is like this.
SELECT table1.*, table2.* -- select everything from table1 and table2
FROM table1
INNER JOIN table2 ON table1.field1 = table2.field1 -- here you put what 2 columns (at least) match the tables.MekaC wrote:
I have tables with different names and none match.
If no tables match then you can't connect them with your login code, but why would you want to anyway? I don't think you are using the right words to expain youself.
-
Here are my tables :) :
Table structure for table `categories`
CREATE TABLE `categories` (
`id` int(30) NOT NULL,
`name` varchar(250) NOT NULL,
`description` text NOT NULL,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `comments`CREATE TABLE `comments` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL,
`comment` text NOT NULL,
`date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `forum_views`CREATE TABLE `forum_views` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `friendship`CREATE TABLE `friendship` (
`friend_id` int(11) NOT NULL,
`receiver` varchar(30) NOT NULL,
`sender` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `member`CREATE TABLE `member` (
`member_id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `messages`CREATE TABLE `messages` (
`messageid` int(11) NOT NULL,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`message` varchar(5000) NOT NULL,
`date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Table structure for table `myfriends`CREATE TABLE `myfriends` (
`friend_id` int(11) NOT NULL,
`myid` varchar(30) NOT NULL,
`myfriends` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-
Here are my tables :) :
Table structure for table `categories`
CREATE TABLE `categories` (
`id` int(30) NOT NULL,
`name` varchar(250) NOT NULL,
`description` text NOT NULL,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `comments`CREATE TABLE `comments` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL,
`comment` text NOT NULL,
`date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `forum_views`CREATE TABLE `forum_views` (
`id` int(30) NOT NULL,
`topic_id` int(30) NOT NULL,
`user_id` int(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `friendship`CREATE TABLE `friendship` (
`friend_id` int(11) NOT NULL,
`receiver` varchar(30) NOT NULL,
`sender` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `member`CREATE TABLE `member` (
`member_id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
-- Table structure for table `messages`CREATE TABLE `messages` (
`messageid` int(11) NOT NULL,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`message` varchar(5000) NOT NULL,
`date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Table structure for table `myfriends`CREATE TABLE `myfriends` (
`friend_id` int(11) NOT NULL,
`myid` varchar(30) NOT NULL,
`myfriends` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
--
I have edited this post to remove the hex dump of the image - it made the thing impossible to read. Having given us your table structures how are they meant to link together? And what are you trying to link? Try sharing just one of your queries that doesn't work so at least we've got something to start on
-
OK, but what is the question now?
-
Hey :) Ive tried the INNER, LEFT, RIGHT join but it doesnt seem as if my tables are connecting. I have tables with different names and none match. I also have a main table(login/register) and want the rest to connect to that. How do I go about doing this? Thank ya :)