MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2013, 11:01 AM
pi4r0n pi4r0n is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 pi4r0n User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 20 sec
Reputation Power: 0
SELECT with INNER JOIN to display only one record

I was wander whether someone could help me with a query problem I am having

I have the following tables with data

cart_session
q_id userid itemid quanity datetime_cart
126 1 10 1 2012-01-16 14:55:26
125 1 23 1 2012-01-16 14:56:26

shop_details
s_id sessid firstname surname email address ordertype orderstatus postcode datetime
20 1 Bob Smith bob@smith 145 Address Pay started xx21 x1 2012-01-16 14:56:26

When I execute the below query I get the following resuls

Quote:
SELECT cart_session.Q_id, cart_session.userid, cart_session.itemid, cart_session.quanity, cart_session.datetime_cart ,shop_detail.s_id, shop_detail.sessid, shop_detail.firstname, shop_detail.surname, shop_detail.email, shop_detail.address, shop_detail.ordertype, shop_detail.orderstatus, shop_detail.postcode ,shop_detail.datetime FROM shop_detail INNER JOIN cart_session ON cart_session.userid=shop_detail.sessid


Result
q_id userid itemid quanity datetime_cart s_id sessid firstname surname email address ordertype postcode datetime
126 1 10 1 2012-01-16 14:55:26 20 1 Bob Smith bob@smith 145 Address Pay started xx21 x1 2012-01-16 14:56:26
125 1 23 1 2012-01-16 14:56:26 20 1 Bob Smith bob@smith 145 Address Pay started xx21 x1 2012-01-16 14:56:26

But I only would like to get one top record. Do you think you would be able to help me with my problem.

Kind Regards;

Arek

Reply With Quote
  #2  
Old January 16th, 2013, 12:07 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 48 m 25 sec
Reputation Power: 1485
Without an ORDER BY clause the concept of 'top' doesn't really mean a great deal as the order the data is returned is not guaranteed. What column would you use to define which is the top row in your example? Add an ORDER BY clause (probably DESC) on that column and a LIMIT 1 to only get the single row.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SELECT with INNER JOIN to display only one record

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap