I tried to get the max value corresponding row and group_concat all the email address. MySql table: expected output: I tried the following query: but it gave wrong result: instead of id 1 I am getting id 2. If I remove the group_concat it gives the correct output. Answer If you want the id of the row with the…
Tag: mysql
MySQL query for selecting distinct rows with all possible values in a column
Here’s my DB table named ‘test_tbl’: id type 1 A 1 B 1 C 1 D 2 A 2 B 2 C 2 D 3 A 3 B 4 A 4 D Here every ‘id’ can have at most 4 possible values (A,B,C,D) for ‘type’ column. I want to find out those ids who don’t have all four values in
Non-matching records using SQL IN
Lets say I have a list of employee names and I want to select all rows with those names: Perhaps Jane and Joe don’t exist in this table. How can I create a query that identifies items in my list that don’t exist at all. I’m not looking for any specific format as the returned result; it can b…
MySql Join Tables With Sum Of A Column
I have 3 tables in total category with columns category_id and category_name server with columns server_id, category_id, server_name and server_url server_hit with columns id, server_id, hit_count, day_date Here in the server_hit table, I am storing how many times a web server is being accessed daily. And in …
Simplification of SQL Query
SQL is not my specialty. I have a working query that accomplishes what I need it to, but I know there has got to be a cleaner way of accomplishing my goal. The query should return: – Name – Date of …
Laravel Eloquent Equivalent for MYSQL DISTINCT query multiple columns
Is there an equivalent query for this in eloquent? Answer Try something like this:
How to perform Many to Many Relationship Filter Query
I want to perform a query in MySQL based on a filter. First of all, the two tables that will be used in the query are the following: Equipment: Field Type Id PK, Integer Name Varchar(50) Recipe: Field Type Id PK, Integer Name Varchar(50) The relationship between the two tables is Many-to-Many, so there is a p…
Calculate returns and insert into another table
I have a table MF_NAVs which holds daily NAVs of mutual funds. I want to calculate the absolute returns over 1 day, 7 day, 15 days, 1 month, 3 month, 6 month, 1 year, 3 year, 5 year & since …
how can i find unique conversation from table in sql
I Have this table: [Messages table] I need to find the number of uniqe conversation – conversation is define as senderid sent msg to reciverid, and reciverid has replied (no matter how many times or …
how to select rows with no null values (in any column) in SQL?
I have a table called table1 It has 100 columns: {col1, col2, …,col100} I understand how to SELECT rows not containing null values in a specific column for instance col1: How do I SELECT all rows that do not contain null values in any column Attempt but this returns an error in MySQL (which I am using) …