Skip to content

Tag: sql

COUNT DISTINCT with CONDITIONS

I want to count the number of distinct items in a column subject to a certain condition, for example if the table is like this: If I want to count the number of distinct tags as “tag count” and count the number of distinct tags with entry id > 0 as “positive tag count” in the same t…

make text column as unique key

i want to make a table in MySQL server with mediumtext column as UNIQUE KEY but this made an error when I change the type of `name` to varchar .. it works! can you tell if i can to make text column as UNIQUE KEY Answer Basically you can not use Text column as UNIQUE key. Because practically such a

Rename single column in SELECT * in SQL, select all but a column

here is what I’m trying to do- I have a table with lots of columns and want to create a view with one of the column reassigned based on certain combination of values in other columns, e.g. Name, Age, Band, Alive ,,, <too many other fields) And i want a query that will reassign one of the fields, e.g.…

Make column not nullable in a Laravel migration

I’m writing a migration to make certain columns in a table nullable right now. For the down function, I of course want to make those columns not nullable again. I looked through the schema builder docs, but couldn’t see a way to do this. Any help would be appreciated. Answer Prior to Laravel 5, th…

How do I put an ‘if clause’ in an SQL string?

So here’s what I want to do on my MySQL database. I would like to do: If that would not return any rows, which is possible through if(dr.HasRows == false), I would now create an UPDATE in the purchaseOrder database: How would I be able to make this process a little shorter? Answer For your specific quer…