Skip to content
Advertisement

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

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

Advertisement