Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/306134-doing-a-mysql-sql-query-from-2-tables/
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.