Solved

SQL Query inner join?

Posted on 2008-06-18
3
299 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

726 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