I’m just trying to see if a particular user has a single resulting row of an inner join between these two tables:
create table course
(
id int primary key auto_increment,
name varchar(255)
);
create table persons
(
id int primary key auto_increment,
username varchar(255),
courseid int,
foreign key (courseid) references course(id)
)
Basically my query goes:
“If user SERGIO is in any course that starts with the letter SVU?” If there is any resulting row, I’d like to return true in my PHP code.
The following will simply return a single row with a column called
foundif a course starting withSVUvia theLEFT()function is found forSERGIO. TheDISTINCTserves to deduplicate multiple rows if the user matches multiple courses beginning withSVU.Here is an example
I assume you already know how to query this in PHP and fetch the result with whatever MySQL API you are using (MySQLi, PDO, or the old
mysql_*())