0

Hope you can help me. I have 2 tables in my MqSQL database.

Table 1.

speedywebs_data

cardid
1
2
3
4

Table 2:

Speedywebs_results
resultid / card1 / card2
1 / 2 / 1
2 / 4 /4

my problem is, i want to get all posts in speedywebs_data table, but only cardid's whos not listed in the speedywebs_results cardid1. How can i do that?

Kevin Lund
  • 159
  • 1
  • 15

2 Answers2

1
SELECT speedywebs_data.*
FROM
  speedywebs_data
WHERE
  cardid NOT IN (SELECT card1 FROM Speedywebs_results WHERE card1 IS NOT NULL)

or you could use also this:

SELECT speedywebs_data.*
FROM
  speedywebs_data LEFT JOIN Speedywebs_results
  ON speedywebs_data.cardid = Speedywebs_results.card1
WHERE
  Speedywebs_results.card1 IS NULL
fthiella
  • 48,073
  • 15
  • 90
  • 106
1

You wanna check if a value doesn't exist ?

So use... NOT EXISTS.

select cardid
from speedywebs_data swd
where not exists (select null
                  from speedywebs_results swr
                 where swr.card1 = swd.cardid)
Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122