473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to select table based on id even/odd in another table

Hi, I want to ask. i have 2 quiz tables that consists of quizzes and also student table. i want to select the quiz table based on when the student register id even, the student will get quiz table set 1, and if student id is odd, get the second quiz table.
i have set the id as primary key in student table
can anyone help mee?

im using php language and mysql.
Dec 10 '18 #1
2 5231
Luuk
1,047 Expert 1GB
Use the MOD function

Expand|Select|Wrap|Line Numbers
  1. SELECT MOD(1,2), MOD(2,2), MOD(3,)
This returns: 1,0,1
Dec 14 '18 #2
AjayGohil
83 64KB
Hi,

you can use store procedure and pass student Id as parameter.

Expand|Select|Wrap|Line Numbers
  1. DELIMITER $$
  2.  
  3. CREATE PROCEDURE GetCustomerLevel(IN  studentId Int)
  4. BEGIN
  5.  
  6.     IF ((studentId%2)==0) THEN
  7.         select *from quiz_table1;
  8.     ELSE
  9.         select *from quiz_table2;
  10.     END IF;
  11.  
  12. END$$
  13.  
  14. DELIMITER ;
  15.  
  16.  
or you can use select If() statement in following way:

Expand|Select|Wrap|Line Numbers
  1. SELECT IF((studentId%2)==0),select *from quiz_table1,   select *from quiz_table2) from student;

you can refer following site for creating store procedure in mysql :


https://dev.mysql.com/doc/refman/8.0...procedure.html
Mar 4 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike | last post by:
Here is my situation; I have two tables in a MS-SQL DB. One table with dollar amounts and service codes. I have a second table that I want to move some information into from the first table. The...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
3
by: bitoulis | last post by:
Hi, is it possible to use the records of a table as the field names of another table? If yes, how is it done? Thanks in advance Laertes
0
by: Leonardo Gangemi | last post by:
How to align right a table based on another table created dinamically? Leonardo
3
by: turtle | last post by:
I have Two tables (Table1 and Table2). Both tables have a common field called part number. Table 1 contains an extra field that i would like to update table 2 to match if the part number matches....
4
by: Farraige | last post by:
Hi I need your help... I am implementing the method that updates given table (table is represented as list of lists of strings) according to other table (some kind of merging)... This method...
3
by: Ronald S. Cook | last post by:
I have a table of keywords (hundreds/thousands of records): KeywordID KeywordName --------- ----------- 1 Apple 2 Orange 3 Pear I then have a table of...
2
by: Haas C | last post by:
Hi all! I am new to this and trying to learn as best as i can. This group is defiintely helpful in that regards. Anyways, I was wondering if someone can help me with this: I have a table...
1
by: Arielle | last post by:
Problem: I have a few related tables that collects information about a given publication. The information collected varies based on the type of collection and is stored in a few different tables. ...
1
by: Gugyu | last post by:
I have a table AVI with the following relevant structure: POLY_NUM key LKP SITE1 SITE2 SITE3 Y2BH I have a lookup table SILKP with: LKP
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.