Retrieve unique data from the MYSQL database
source link: https://www.codesd.com/item/retrieve-unique-data-from-the-mysql-database.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Retrieve unique data from the MYSQL database
I have a table in my database which contains 5 rows. I am trying to write an sql statement that will retrieve all rows which only have 1 agency assigned to them.
case_id agency_ID
1 4
2 4
3 3
4 2
4 4
To clarify I would like to select the required rows (and any further rows) but only if the case_id is unique. Any rows with duplicates would be ommited.
I have tried to use DISTINCT(case_id), COUNT(*) to count all rows but it doesn't work and it's slowly sapping away my soul. It is probably an easy fix, but for the life of me I just can't see it.
Hope this is enough information to go on. Any help would be greatly appreciated.
SELECT * FROM your_table GROUP BY case_id HAVING COUNT(agency_ID) = 1
Related Articles
Retrieving data from the MySQL database using PHP, viewing as editing
Get a sorted subset of data from the mysql database to use in pagination
How do I make a script to retrieve specific data from a MYSQL database?
How to synchronize a postgresql database with data from the mysql database?
Download the data from the mysql database to a Word document in php
How do I get yesterday / today data from the MySQL database?
how to import data from the mysql database to datagridview
Getting old data from the mysql database when adding div
How do I view data from the MySQL database on a PHP site?
how to get data from the Mysql database stored in a string format
View data from the mysql database
How to delete data from the mysql database with angularjs $ http request?
Retrieve data from the mysql database in this code
How to retrieve data from the mysql database by joining 5 different tables
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK