Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

Vishal Sharma

"SELECT family.* ,charity.charityName FROM family join charity WHERE charity.user_id = family.createdby AND family.streetAddress in (SELECT family.streetAddress FROM family GROUP BY family.city,family.streetAddress HAVING count(*) > 1 AND ) ORDER BY family.streetAddress ASC LIMIT $offset,$limit"

this Query produces following result as shown in image

https://drive.google.com/file/d/0B3RNacAE6rR5Rk8tUUI2Q3B3X3M/view?usp=sharing

blue marked is problem record that should not come.

Above Query list all records with similiar street address but failed to get only those records with similiar address && city. I need to get only those records which are having same city and streetaddress . is there any way to apply and logic for groupby

ryanyuyu

Your main select's WHERE clause only checks for a matching address :

AND family.streetAddress in (....)

which will match any address found in your subselect, even if it belongs to the wrong city. The subselect currently only returns the address, but not the matching city. That's the problem.

I'm not sure that this will fix your problem, but you can try to can change the subselect into a nested table expression and match on both address and city. Maybe something along the lines of

SELECT family.* --and other main select stuff
WHERE charity.user_id = family.createdby 
AND exists --similar to count(*) > 1

select streetAddress, city 
from (
    (SELECT family.streetAddress, family.city 
        FROM family 
        GROUP BY family.city,family.streetAddress 
        HAVING count(*) > 1) AS subSelect
) 
WHERE family.streetAddress = subSelect.streetAddress 
    AND family.city = subSelect.city

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

From Dev

How to select records from mysql along with one previous record

From Dev

write linq similiar where in select from with inner join in sql query

From Dev

Using sub-query to SELECT MAX value along with LEFT JOIN

From Dev

MySQL : Select three last item INNER JOIN

From Dev

MySQL select a single record from highest join value from multiple tables with multiple records

From Dev

MySQL - JOIN based on value of column?

From Java

Select Mysql with empty value on join

From Dev

how to select records based on recent date in mysql

From Dev

How to select records based on 2 dates in mysql

From Dev

MySQL - Join records where all sub records have a value

From Dev

select data based on three values from mysql

From Dev

mysql group records based on a column value

From Dev

Select field based on value in MySQL

From Dev

join 2 mysql select based on text field

From Dev

AND operation within mysql records

From Dev

SQL query to filter records based on a particular column value along with descending date of insertion

From Dev

MySQL join a different table based on field value

From Dev

Select value based on value of another row in mysql

From Dev

Mysql - Populate data in one column based on join with three different fields

From Dev

How to SELECT multiple columns with MySQL based on multiple records?

From Dev

Select records based on the postal code and it's radius in MySQL

From Dev

mySQL select records based on difference to previously selected record

From Dev

How to select the group of most recent records based on specific conditions in MySQL

From Dev

how do i select multiple mysql records based on checked checkboxes?

From Dev

How to SELECT multiple columns with MySQL based on multiple records?

From Dev

Select records based on the postal code and it's radius in MySQL

From Dev

A troubling MySQL Join operation

From Dev

SELECT records based on criteria

Related Related

  1. 1

    Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

  2. 2

    How to select records from mysql along with one previous record

  3. 3

    write linq similiar where in select from with inner join in sql query

  4. 4

    Using sub-query to SELECT MAX value along with LEFT JOIN

  5. 5

    MySQL : Select three last item INNER JOIN

  6. 6

    MySQL select a single record from highest join value from multiple tables with multiple records

  7. 7

    MySQL - JOIN based on value of column?

  8. 8

    Select Mysql with empty value on join

  9. 9

    how to select records based on recent date in mysql

  10. 10

    How to select records based on 2 dates in mysql

  11. 11

    MySQL - Join records where all sub records have a value

  12. 12

    select data based on three values from mysql

  13. 13

    mysql group records based on a column value

  14. 14

    Select field based on value in MySQL

  15. 15

    join 2 mysql select based on text field

  16. 16

    AND operation within mysql records

  17. 17

    SQL query to filter records based on a particular column value along with descending date of insertion

  18. 18

    MySQL join a different table based on field value

  19. 19

    Select value based on value of another row in mysql

  20. 20

    Mysql - Populate data in one column based on join with three different fields

  21. 21

    How to SELECT multiple columns with MySQL based on multiple records?

  22. 22

    Select records based on the postal code and it's radius in MySQL

  23. 23

    mySQL select records based on difference to previously selected record

  24. 24

    How to select the group of most recent records based on specific conditions in MySQL

  25. 25

    how do i select multiple mysql records based on checked checkboxes?

  26. 26

    How to SELECT multiple columns with MySQL based on multiple records?

  27. 27

    Select records based on the postal code and it's radius in MySQL

  28. 28

    A troubling MySQL Join operation

  29. 29

    SELECT records based on criteria

HotTag

Archive