Jump to content
Sign in to follow this  
webdev1

Doing a MySQL SQL query from 2 tables

Recommended Posts

Hi

I am trying to demonstrate a random number college project by code.

I have a query which works fine getting data from table:

 

SELECT id,Date, GROUP_CONCAT(ball ORDER BY ball) balls
  FROM
     ( SELECT id,Date,Ball1 ball FROM history eh
       UNION
       SELECT id,Date,Ball2 ball FROM history eh
       UNION
       SELECT id,Date,Ball3 ball FROM history eh
       UNION
       SELECT id,Date,Ball4 ball FROM history eh
       UNION
      SELECT id,Date,Ball5 ball FROM history eh
     ) x
 WHERE ball IN (6, 24, 32, 48, 50)
 GROUP
    BY id HAVING COUNT(*) >= 2

 

This will give 3 columns result:

id,Date,balls which match any 2 or more of above numbers

 

I want to join the result with another table starballs which has the same id as above and stores two colums of data Star1 Star2

i.e. id,Star1,Star2

I assume this will be inner join? to keep the data of top query and join it with starballs table.

 

I have tried all sorts and cannot get it working.

Can someone help me with this please.

 

Thanks

Edited by webdev1

Share this post


Link to post
Share on other sites

Hi

I am trying to demonstrate a random number college project by code.

I have a query which works fine getting data from table:

 

SELECT id,Date, GROUP_CONCAT(ball ORDER BY ball) balls

  FROM

     ( SELECT id,Date,Ball1 ball FROM history eh

       UNION

       SELECT id,Date,Ball2 ball FROM history eh

       UNION

       SELECT id,Date,Ball3 ball FROM history eh

       UNION

       SELECT id,Date,Ball4 ball FROM history eh

       UNION

      SELECT id,Date,Ball5 ball FROM history eh

     ) x

 WHERE ball IN (6, 24, 32, 48, 50)

 GROUP

    BY id HAVING COUNT(*) >= 2

 

This will give 3 columns result:

id,Date,balls which match any 2 or more of above numbers

 

I want to join the result with another table starballs which has the same id as above and stores two colums of data Star1 Star2

i.e. id,Star1,Star2

select * FROM starballs WHERE STAR1= 5 AND STAR2=9

I assume this will be inner join? to keep the data of top query and join it with starballs table.

 

I have tried all sorts and cannot get it working.

Can someone help me with this please.

 

Thanks

Edited by webdev1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.