I have a column in a table which might contain null or empty values. How do I check if a column is empty or null in the rows present in a table? (e.g. null or ” or ‘ ‘ or ‘ ‘ and …)
Tag: mysql
Does using “LIMIT 1” speed up a query on a primary key?
If I have a primary key of say id and I do a simple query for the key such as, Will it find one row and then stop looking as it is a primary key, or would it be better to tell mysql to limit its select by using LIMIT 1? For instance: Answer Does using “LIMIT 1” speed up
Join two tables where table A has a date value and needs to find the next date in B below the date in A
I got this table “A”: and this table “B”: Now I am looking for a way to JOIN those two tables having the “value” column in “B” mapped to the dates in “A”. The tricky part for me here is that table “B” only stores the change date and the new value. Now when I need this value in table
Using SELECT for simple BOOLEAN evaluation
I want to test some evaluations without working on any table. For example, you can write I want to achieve something like this: I know that most engines don’t have the concept of a boolean data type, but I don’t know how their internal work (even if I guess everything <> 0 is true, like in C). Anyway, the format
left join returning more than expected
Using the following query table1 returns 16 rows and table2 returns 35 rows. I was expecting the above query to return 16 rows because of the left join, but it is returning 35 rows. right join also returns 35 rows Why is this happening and how do I get it to return 16 rows? Answer LEFT JOIN can return multiple
How can I return pivot table output in MySQL?
If I have a MySQL table looking something like this: company_name action pagecount ——————————- Company A PRINT 3 Company A PRINT 2 Company A PRINT 3 Company B EMAIL Company B PRINT 2 Company B PRINT 2 Company B PRINT 1 Company A PRINT 3 Is it possible to run a MySQL query to get output like this: company_name EMAIL
How do I make the rows of a lookup table into the columns of a query?
I have three tables: students, interests, and interest_lookup. Students has the cols student_id and name. Interests has the cols interest_id and interest_name. Interest_lookup has the cols student_id and interest_id. To find out what interests a student has I do What I want to do is get a result set like where the column name ‘interest_a’ is a value in interests.name
Get number of values that only appear once in a column
Firstly, if it is relevant, I’m using MySQL, though I assume a solution would work across DB products. My problem is thus: I have a simple table with a single column. There are no constraints on the column. Within this column there is some simple data, e.g. I need to get the number/count of values that only appear once. From
Doctrine 2 Query Builder abs Function
This Work: This Don’t Work: The Error: Syntax Error] line 0, col 118: Error: Expected end of string, got ‘(‘ The native doctrine function abs work only on a select part of statment and don’t work on order by part. Obs: 1-) Im avoiding to use NativeQuery. 2-) u.code is a varchar fild on mysql and need to be varchar
How do I add a custom CHECK constraint on a MySQL table?
I am having trouble with this table I want to have a foreign key constraint, and that works. Then, I also want to add a constraint to the attribute status so it can only take the values ‘a’, ‘d’ and ‘u’. It is not possible for me to set the field as Enum or set. Can anyone tell me why