?> Python script from sqlalchemy import create_engineįrom sqlalchemy. Sample code using distinct query by using PHP script and PDO. How to identify the customers who have not purchased or who's id is not appearing in sales table? ('Aus', 'India', 'India') Present in one and not present in other table. INSERT INTO `icc_world_cup` (`Team_1`, `Team_2`, `Winner`) VALUES SELECT DISTINCT sale.c_id, name FROM `sale`, customer WHERE sale.c_id = customer.c_idįind out the list of teams participated in the tournament using the two columns Team_1 and Team_2. We will get distinct customer id from sales table and then link that to get the customer name from customer table. We will try to get the name of the customer who has purchased any product. Same customer may buy more than once so there will be multiple entry for customer in our sales table. One is our customer details and other one is with sales details. Here is a sample output, you will get more detail output when you use sql dump of student table given at the end of this page.ĭown load the SQL DUMP of this student table Distinct records linking two tables. SELECT distinct class, gender FROM `student` order by class To make the list easily readable we will add order by query to this so we can list each class one after other. SELECT distinct class, gender FROM `student` So each class will be returned twice, once with gender equal to male and other one will be when gender equal to female. We know each class have two types of student ( male and female ). Now the distinct query can be applied using two columns. MySQL Count Query DISTINCT query using more than one column of a table postgresql - Calling SELECT DISTINCT on multiple columns - Database Administrators Stack Exchange Calling SELECT DISTINCT on multiple columns Ask Question Asked 5 years, 3 months ago Modified 5 years, 3 months ago Viewed 16k times 6 I am unclear on exactly on, SELECT DISTINCT col1, col2. As you can see only two rows are returned and they are the distinct class in the tableĬounting number of distinct records SELECT COUNT( DISTINCT class ) FROM student
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |