SQL Query Help

Soldato
Joined
5 May 2004
Posts
4,462
Location
Northern Ireland
Hello

I need a little help with my sql query.

I have two tables one being longer than the other and I would like where the driverNo1 - 6 are in Table 1 and are the drivers of person Peter get the race1session1 number

This is my query so far but for some reason it returns everything. I have tried different variations of it and in one case it pulled back 6 copies of each driver

Code:
select driverName from Table1, selection where driverName = selection.driverNo1 or selection.driverNo2 and playerName = 'Peter'

These are my tables:

Table 1
Code:
	driverName	race1session1
	Sebastian Vettel	1
	Mark Weber	2
	Lewis Hamilton	3
	Jenson Button	4
	Fernando Alonso	5
	Felipe Massa	6
	Michael Sch	7
	Nico Rosberg	8
	Robert Kubica	9
	Vitaly Petrov	10
	Rubens Barrichello	11

Table 2
Code:
playerName	driverNo1	driverNo2	driverNo3	driverNo4	driverNo5	driverNo6
Peter	Fernando Alonso	Segio Perez	Jaime Alguersuari	Heikki Kovalainen	Jarno Trulli	Rubens Barrichello
Brian	Sebastian Vettel	Narain Karthikeyan	Jarno Trulli	Jenson Button	Kamui Kobayashi	Segio Perez
Keith	Sebastien Buemi	Jarno Trulli	Jaime Alguersuari	Kamui Kobayashi	Heikki Kovalainen	Narain Karthikeyan
Paul	Jenson Button	Sebastien Buemi	Jarno Trulli	Jaime Alguersuari	Heikki Kovalainen	Narain Karthikeyan
Aaron	Rubens Barrichello	Paul di Resta	Sebastien Buemi	Jaime Alguersuari	Heikki Kovalainen	Narain Karthikeyan
Dave	Narain Karthikeyan	Heikki Kovalainen	Jerome d'Ambrosio	Timo Glock	Jarno Trulli	Jaime Alguersuari

Any help in this matter is appericated. This is not for school/college/uni work.

Thanks,

Peter
 
Last edited:
I understand those words, but not in that order.

What is it you're trying to do?

Looks like a fantasy F1 site? I was going to do one of those this year too :)

I would like find only one person's driver selections in the results table and pick out the girdposition

Yes it is. Got a fair chunk of it done.

Regards,

Blackvault
 
Hi Folks.

Sorry looking at my tables I shouldn't have included the ID numbers for the Table1. THose are actually the autoNumbers in the table so they don't relate to anything really. Does that affect the code you have suppiled?

Thanks,

Blackvault
 
Back
Top Bottom