Solved

SQL Query inner join?

Posted on 2008-06-18
3
296 Views
Last Modified: 2010-08-05
Hi there, need a query to fit the below, I have a similiar query where I've used inner joins but this requires 'where' from multiple tables.

Here it is in pseudo (kind of):

Select EventTitle, EventDateTime FROM dbo.Events Where Event ID=@EventID

Select CustID, FullTickets, HalfTickets, FreeTickets, MembersTickets, Price, PaymentMethod, StaffID, Notes, BookingID WHERE EventID=@EventID FROM dbo.Bookings

Select FirstName + ' ' + LastName As Name from dbo.customers WHERE CustID=@CustID (all CustID returned from above Bookings table query)

I need this all to be returned in one row though, hope it makes sense!

Thanks!
0
Comment
Question by:garethh86
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
scgstuff earned 500 total points
ID: 21818417
Try this:

Select e.EventTitle, e.EventDateTime, b.CustID, b.FullTickets, b.HalfTickets, b.FreeTickets, b.MembersTickets, b.Price, b.PaymentMethod, b.StaffID, b.Notes, b.BookingID, c.FirstName + ' ' + c.LastName As Name  
FROM dbo.Events e inner join dbo.Bookings s on e.EventID = b.Event_ID
inner join dbo.customers on b.CustID = c.CustID
WHERE e.EventID=@EventID

Shawn
0
 
LVL 7

Author Comment

by:garethh86
ID: 21818467
you got a couple of letters round the round way but i shuffled it round and it works! Thanks for the quick response! :)
0
 
LVL 5

Expert Comment

by:scgstuff
ID: 21818519
Sorry about that....was doing too much at once and wasn't watching what I was typing.

Thanks,

Shawn
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now