7

Retrieve unique data from the MYSQL database

 2 years ago
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.
neoserver,ios ssh client

Retrieve unique data from the MYSQL database

advertisements

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

I'm a newbie to this and wrote the code below to fetch user data from a MySQL Database and display it in a form for editing and saving. Problem is, it does not work. Any help will be appreciated. <html> <head> <title> Delegate edit form&

Get a sorted subset of data from the mysql database to use in pagination

I have a submissions table where users can vote on the content. I'd like to add functionality to browse through the submissions in order of votes. I want to limit the number of submissions that appear on each page and implement a pagination system. S

How do I make a script to retrieve specific data from a MYSQL database?

I made a simple search to retrieve customer data from a database. So far I've only been able to make it successful display the current table data on the webpage but I can't get the search function to retrieve specific data. I'm having 0 database acce

How to synchronize a postgresql database with data from the mysql database?

I have an application at Location A (LA-MySQL) that uses a MySQL database; And another application at Location B (LB-PSQL) that uses a PostgreSQL database. (by location I mean physically distant places and different networks if it matters) I need to

Download the data from the mysql database to a Word document in php

I am trying to download the data saved within mysql database to a word document using php. The code I have at the minute is meant to work as follows, Display all data within the student table of the database Click the download button which downloads

How do I get yesterday / today data from the MySQL database?

I would like to retrive a TODAY'S data from the database, but I don't know how to do it. I would actually want to get the data from NOT the past 24 hours, I just want today's data (so based on the actual server time). I would also like to get data wh

how to import data from the mysql database to datagridview

i have a table in mysql database named cms.order and i am working on a widows form using C#. How can i show the data from the table in database in the datagridview of the windows formYou can use the following code to read the table data from database

Getting old data from the mysql database when adding div

I have a main page on which I have a button which opens a popup. When closing this popup then I have a script which calls to a php file to select data from the database. This selected data will be appended to a div in the main page: if (win.closed !=

How do I view data from the MySQL database on a PHP site?

What I have: My current view What I want: 6 items next to each other from the same database Unfortunately my previous question wasn't answered to the extent as I wanted it to, so here's another question. The code: <?php # DISPLAY COMPLETE PRODUCTS PA

how to get data from the Mysql database stored in a string format

i have stored date in string format in the MySQL database . i have to generate monthly(0-31) report of data but query gives wrong results because date is store in string format.... any one can tell me how to solve this problem and what will be the qu

View data from the mysql database

I am trying to display all the data from the database I created, however it does not display all the data only the data that is recently added. Can someone tell me what is wrong with my code? Thank you very much! <?php include 'dbconnect.php'; $query

How to delete data from the mysql database with angularjs $ http request?

Here is the code $scope.Delete = function(customer ){ $http({ method: 'get', url: 'rest/customers', data: {customers:customer.custId}, }).then(function successCallback(response) { $scope.customers.splice($scope.customers.indexOf(customer), 1); }); }

Retrieve data from the mysql database in this code

I am creating an Invitation Card app for my upcoming event which will be held. My code successfully inserts the data into mysql database named booking having table name data. But there is problem with retrieving. When I fill the form and submit, it s

How to retrieve data from the mysql database by joining 5 different tables

I am trying to retrieve data from mysql database from 5 different table but it did not work as it should and it did not display anything. tables are : site_info site_coordinates owner_info subcontractor_info company_info site_info: siteID companyID -

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK