I’ve been hiding here for several months now and am learning a lot from reading other questions, but this is the first time I have been brave enough to ask him!
SELECT * FROM tableA a
JOIN tableB b ON b.tableBid = a.tableBid
WHERE a.tableAcol = 'paramValue';
I only have 39 rows in table B, and for each of them there is a row in tableA for paramValue with a suitable tableBid, so I expect to get 39 rows back. And indeed, in another instance of the database, I do.
I do not see significant differences in the instances, although this may be ignorance, but in this new instance I get only 7 records with the same request.
If I changed the request to
SELECT * FROM tableA a
LEFT JOIN tableB b ON b.tableBid = a.tableBid
WHERE a.tableAcol = 'paramValue';
or
SELECT * FROM tableA a
LEFT JOIN tableB b ON a.tableBid = b.tableBid
WHERE a.tableAcol = 'paramValue';
then I get 39 rows that I expect using matching a.tableBid b.tableBid in all cases and no zeros
. - , .
,
CREATE TABLE tableB (
tableBid varchar(30) NOT NULL PRIMARY KEY,
nameB varchar(25) NOT NULL ,
description varchar(40) NOT NULL);
CREATE TABLE tableA (
userID varchar(30) NOT NULL,
tableBid Varchar(30) NOT NULL,
info varchar(10) NOT NULL,
PRIMARY KEY(userID, tableBID));
insert into tableB (tableBid, nameB, description)
values
('a', 'a name', 'blah'),
('b', 'b name', 'blah'),
('c', 'c name', 'blah'),
('d', 'd name', 'blah');
insert into tableA (userID, tableBid, info)
values
('deel','a', 'blah'),
('deel','b', 'blah'),
('deel','c', 'blah'),
('deel','d', 'blah');
SELECT * FROM tableA a
LEFT JOIN tableB b ON b.tableBid = a.tableBid
WHERE a.userID = 'deel';
4 :
deel a blah a a name blah
deel b blah b b name blah
deel c blah c c name blah
deel d blah d d name blah
SELECT * FROM tableA a
JOIN tableB b ON b.tableBid = a.tableBid
WHERE a.userID = 'deel';
deel d blah d d name blah
SHOW CREATE TABLE tableA
CREATE TABLE tablea ( userID varchar (30) NOT NULL, tableBid varchar (30) NOT NULL, info varchar (10) NOT NULL, (userID, tableBid)
) ENGINE = Xeround DEFAULT CHARSET = latin1
SHOW CREATE TABLE tableB
tableb ( tableBid varchar (30) NOT NULL, nameB varchar (25) NOT NULL, description varchar (40) NOT NULL, (tableBid)
) ENGINE = Xeround DEFAULT CHARSET = latin1