Skip to content

Tag: mysql

How to compare 2 columns of 2 different tables on Mysql

I did something like this with PHP and it works. My question is how to do the same with one sql statement, instead of writing 3 different and doing the array_diff/implode thing. Unfortunately I have limited sql knowledge but I’m pretty sure it’s possible, I think with JOIN but after 2 hours still …

Prepared Statement does not use expected index

I have a very large table of IOT sample that I’m trying to run a relativly simple query against. Running the query normally using the MySql CLI returns a result in ~0.07 seconds. If I first prepare the query either via PDO or by running a SQL PREPARE statement then the request takes over a minute. I&#82…

PHP display name of login user

I am trying to display the name of a user when they are logged in. My code uses $_SESSIONS to store the name, but since there no input in my login in page, the name doesn’t get assign and it ends up being just hello, instead of something like hello, John Smith. I’ve tried using sql to select the n…

how to exclude a rule in laravel validation

I am building a user’s resignation inside the dashboard with Form Request Validation. it works well in store resource, but I need to exclude the password role in updating resource, so if the user leaves it empty I will store the old password my validation file Answer In this case just use ‘sometim…

Select subquery error Subquery returns more than 1 row

Table 1 Table 2 #1242 – Subquery returns more than 1 row I am trying to get concatenated values from the other table with matching ids from this table that I have given in the foreign key like this: Edit: I changed the code: New Error:#1054 – Unknown column ‘products_brands.product_id’…

How do I download a pdf blob file from database?

I’m trying to download a pdf file from the database stored as a blob datatype using the code blow, right now I’m only able to view the file as .php and not .pdf. The $result->mime contains the data-type of the file as application/pdf. The $result->pdf_file contains the PDF file itself as BLO…

Query that only selects unique data

I just can’t make a request that will count only unique records. There is a table: bbs with columns: to_id – to whom from_id – from whom You need, for example, this data: That is, for example, we are 1. And it should count not 5, as it currently thinks, but 3. You need to select 2 columns, o…