473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Write Sql query to select all username who had nokia handsets "N72" in 2008

Write a my sql query to select all username who had nokia purchased handsets "N72" in the year 2008.

tables given below:

Thanks

Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.2.0.1
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Host: localhost
  6. -- Generation Time: Nov 02, 2010 at 10:51 AM
  7. -- Server version: 5.1.37
  8. -- PHP Version: 5.3.0
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12. --
  13. -- Database: `intTest`
  14. --
  15.  
  16. -- --------------------------------------------------------
  17.  
  18. --
  19. -- Table structure for table `handsets`
  20. --
  21.  
  22. CREATE TABLE IF NOT EXISTS `handsets` (
  23.   `handsets_id` varchar(10) NOT NULL,
  24.   `user_id` varchar(10) NOT NULL,
  25.   `handsets` varchar(20) NOT NULL,
  26.   `purchase_date` varchar(20) NOT NULL
  27. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  28.  
  29. --
  30. -- Dumping data for table `handsets`
  31. --
  32.  
  33. INSERT INTO `handsets` (`handsets_id`, `user_id`, `handsets`, `purchase_date`) VALUES
  34. ('1', '1', 'n72', '2008-03-19'),
  35. ('2', '1', '1610', '2009-03-19'),
  36. ('3', '1', '3210', '2009-03-19'),
  37. ('4', '2', 'n72', '2008-03-19'),
  38. ('5', '3', '6680', '2009-03-19'),
  39. ('6', '3', '6681', '2009-03-19'),
  40. ('7', '3', 'n72', '2009-03-19');
  41.  
  42. -- --------------------------------------------------------
  43.  
  44. --
  45. -- Table structure for table `users`
  46. --
  47.  
  48. CREATE TABLE IF NOT EXISTS `users` (
  49.   `user_id` varchar(10) NOT NULL,
  50.   `username` varchar(30) NOT NULL
  51. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  52.  
  53. --
  54. -- Dumping data for table `users`
  55. --
  56.  
  57. INSERT INTO `users` (`user_id`, `username`) VALUES
  58. ('1', 'nipun'),
  59. ('2', 'rohit'),
  60. ('3', 'sumit');
  61.  
  62.  
Nov 2 '10 #1
2 2232
First the tables:

Expand|Select|Wrap|Line Numbers
  1. -- Table structure for table `users`
  2. --
  3.  
  4. CREATE TABLE `users` (
  5.   `user_id` int(11) NOT NULL auto_increment,
  6.   `username` varchar(30) NOT NULL,
  7.   PRIMARY KEY  (`user_id`)
  8. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
  9.  
  10.  
  11. -- Table structure for table `handsets`
  12. --
  13.  
  14. CREATE TABLE `handsets` (
  15.   `handsets_id` int(11) NOT NULL auto_increment,
  16.   `user_id` int(11) NOT NULL,
  17.   `handsets` varchar(20) NOT NULL,
  18.   `purchase_date` date NOT NULL,
  19.   PRIMARY KEY  (`handsets_id`)
  20. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
Second the query:

Expand|Select|Wrap|Line Numbers
  1. SELECT username FROM users ,handsets
  2. WHERE users.user_id=handsets.user_id
  3. and handsets='n72'
  4. and purchase_date between '2008-01-01' and  '2008-12-31'
Nov 2 '10 #2
Thanks a lot...it works
Nov 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
2
by: Himmel | last post by:
Hello! The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
4
by: matias.cornejo | last post by:
I have a table with 1.000.000 registers and I want to find the register in a position 25.000. I don't want to use a cursor, how can I do it in other way? Thenks in advance
0
by: sara | last post by:
Hi - I have a table keeping track of employees' jobs in a location. So, Store #1 Manager #353, AsstMgr #556 Store #2 Manager #776, AsstMgr #132 etc. The table is Date StoreNum MgrNum ...
0
by: harik82 | last post by:
Hi All, In one of my UDF i have writen the query as shown below, but it is throwing sme errors. Can any one help me to solve this problem.....very urgent.... IF ((select...
1
by: viki1967 | last post by:
Hi. I have a table in a mysql db: NAME ROLE DATE TYPE MARK STR 2008-04-28 B KARL MAN ...
2
by: gagandeepsngh | last post by:
'Code for selecting a particular data from database '***** START ***** sSQL = "SELECT name FROM trans" cmd = New OleDbCommand(sSQL, con) Dim reader As OleDbDataReader = cmd.ExecuteReader()...
4
by: micropos | last post by:
hi everyone,who can help me solve the problem?this is my code: <?php include 'C:/wamp/www/micropos/condb1.php'; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could...
2
by: Octo Siburian | last post by:
How do I interpret the declaration time 'AM' and 'PM' in Ms.access Query I have Query Select in vb6.0 to get data from Ms.access database SQLSelectdbRAS = "SELECT a.DN, b.DIN, c.PIN,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.